将Struts2,Hibernate与Enterprise应用程序集成时会发生JasperException

时间:2012-12-17 18:27:05

标签: java hibernate struts2 web-frameworks

我有一个使用Struts2构建的Web应用程序,Hibernate和它工作正常。

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

然而,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应用程序并进行清理和构建。 Web应用程序是可行的。

补充:

我在企业应用程序中添加了库,如下图所示,并更改了filter。但错误仍然存​​在。 enter image description here enter image description here

2 个答案:

答案 0 :(得分:0)

在将Web应用程序正确添加为Enterprise应用程序作为JavaEE模块时,请检查是否已配置buildpath / classpath。可能存在一些未解析的依赖项,因此无法找到Struts调度程序。

注意:自Struts版本2.1.3起,不推荐使用FilterDispatcher过滤器。如果您使用的是最新版本的Struts2(&gt; 2.1.3),请使用

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

代替。 因为你得到了JasperException。你需要知道一些事情为什么会发生这种异常:

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

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

    1. Jsp代码编写不正确。

答案 1 :(得分:0)

就像@DarkHorse提到的那样,您不应该使用FilterDispatcher,请将其更改为org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

您似乎没有包含所有依赖项。确保在类路径中有以下依赖项:
enter image description here