【问题标题】:Struts dispatcher cannot be found找不到 Struts 调度程序
【发布时间】:2014-04-18 09:18:30
【问题描述】:

错误来了:

找不到 Struts 调度程序。这通常是由于使用没有关联过滤器的 Struts 标签造成的。 Struts 标签仅在请求通过其 servlet 过滤器时可用,该过滤器会初始化此标签所需的 Struts 调度程序。

我的 struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" 

    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>Struts2 Login</display-name>

<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>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd">
 <struts>
<constant name="struts.action.excludePattern" value="/ServletToExcludeFromStruts*"    />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">

    <action name="hello" class="com.struts.action.HelloWorldAction"
        method="execute">
        <result name="success">/HelloWorld.jsp</result>
    </action>
    </package>
 </struts>

以及所需的 jar 文件...[如果我错了,请纠正我]

commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.11.jar
xwork-2.0.4.jar
commons-collections-3.0.jar
commons-fileupload-1.2.1.jar
commons-lang-2.4.jar
commons-io-1.3.2.jar
javassist-3.0.jar

【问题讨论】:

    标签: java jsp struts2


    【解决方案1】:

    你的 web.xml 和 struts.xml 没问题。

    JAR 版本与the required dependencies for Struts 2.0 略有不同:

    xwork 应该是 2.0.7commons-io 应该是 1.0,以此类推。

    顺便说一句,由于您今天似乎是从一个新的 Struts2 项目开始,我强烈建议您从最新的 Struts2 库开始至少,原因如下:

    1. 使用 6 年历史的图书馆绝对没有一个理由;如果你的公司有这个规则,那就和你的老板一起争取改变这个规则,特别是针对以下论点;
    2. 2.3.15.3 之前的 Struts2 版本受 serious security bug 影响;
    3. Struts2 在功率、效率、速度、错误修复方面有了显着的进步,并且已经弃用了几个旧的和有问题的库,如 Struts2-Dojo 和前面提到的 FilterDispatcher(从 Struts 2.1.3 开始,您必须使用新的过滤器,即是StrutsPrepareAndExecuteFilter,写在FilterDispatcher documentation)
    4. 有了新的 Struts2 版本,您可以使用新的插件,这将为您的 webapp 添加真正的价值,尤其是:

    然后使用最新的库(当前为 2.3.16.1)开始一个新项目,最好使用 Maven,或者手动关注 the required dependencies and their versions

    Download a Release of Apache Struts

    【讨论】:

    • 现在我更改了 jar 文件,然后异常就像 org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/opensymphony/xwork2/config/ContainerProvider
    【解决方案2】:

    我认为您已经交换了两个文件(struts.xml 和 web.xml)的内容,这就是您收到此错误的原因。

    【讨论】:

      猜你喜欢
      • 2011-01-24
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      相关资源
      最近更新 更多