java - Struts2、Hibernate与企业应用程序集成时出现JasperException

标签 java hibernate struts2 web-frameworks

我有一个使用 Struts2、Hibernate 构建的 Web 应用程序,它运行良好。

我在 NetBean 中创建了一个新的企业应用程序。我构建的 Web 应用程序已作为 Java EE 模块添加到企业应用程序中。我选择客户端模块作为 Web 应用程序并尝试运行企业应用程序

但是,网络应用程序无法运行。它告诉我

org.apache.jasper.JasperException: The Struts dispatcher cannot be found.  

This is usually caused by using Struts tags without the associated filter. 

Struts tags are only usable when the request has passed through its servlet filter, 

which initializes the Struts dispatcher needed for this tag. - [unknown location]

Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

一旦我从企业应用程序中删除 Web 应用程序并进行清理和构建。该网络应用程序是可以运行的。

补充:

我已经在企业应用程序中添加了库,如下图所示,并更改了过滤器。但错误仍然出现。 enter image description here enter image description here

最佳答案

在将 Web 应用程序添加为企业应用程序作为 JavaEE 模块时,检查是否正确配置了构建路径/类路径。可能存在一些 Unresolved 依赖关系,因此无法找到 Struts 调度程序。

注意:自 Struts 2.1.3 版起,FilterDispatcher 过滤器已被弃用。如果您使用的是最新版本的 Struts2 (> 2.1.3),请使用

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

相反。 既然你得到了 JasperException。您需要了解一些事情为什么会发生此异常:

  • 只要您错过标签或没有正确关闭标签,就会发生这种情况
  • 当你的JSP没有被jasper引擎解析时,它会抛出jasper异常。 意味着如果你没有正确编写jsp代码,并且如果你在jsp中放置了任何不可用的资源,那么我们将得到Jasper异常
  • 以下原因可能会导致 jasper Exception。

    构建路径中缺少 1.jsp-api.jar。

    1. Jsp 代码编写不正确。

关于java - Struts2、Hibernate与企业应用程序集成时出现JasperException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13919877/

相关文章:

Hibernate/JPA 无法进行预加载

java - 如何使用tile拥有一个灵活的网站?

java - 如何将红黑BST转换成数组?

java - 在java中计算S3对象(文件夹)的大小

java - 在 OSGi 框架中使用 Esper

java - Struts java-mysql WSO2部署错误

java - Struts2 验证 - 验证失败时重新填充子项

java.io.IOException : Unable to open "..." as class path, 文件名或 URL

java - JPA @OrderBy 注解 - 排序字符串

spring - 如果没有主键,则使用 spring data jpa 存储库