3

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

我在 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。但仍然出现错误。 在此处输入图像描述 在此处输入图像描述

4

2 回答 2

0

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

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

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

反而。既然你得到了 JasperException。您需要知道几件事为什么会发生此异常:

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

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

    1. jsp代码写不正确。
于 2012-12-20T07:23:11.043 回答
0

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

似乎您没有包含所有依赖项。确保您的类路径中有以下依赖项:
在此处输入图像描述

于 2012-12-20T15:19:15.020 回答