【问题标题】:Error 404 upon Start up of Struts2 in tomcat在tomcat中启动Struts2时出现错误404
【发布时间】:2012-11-23 02:36:33
【问题描述】:

我正在使用 Struts2 制作这个 hello world 应用程序,我遇到了一个

HTTP Status 404 - /HelloStruts2/

这是我的web.xml

<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_3_0.xsd" version="3.0">
  <display-name>HelloStruts2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

   <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

这是我的struts.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.devMode" value="true" />

    <package name="basicstruts2" extends="struts-default">

        <action name="index">
            <result>WEB-INF/index.jsp</result>
        </action>

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

    </package>

</struts>

这是我的应用程序中的 jar 列表

commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.15.0-GA.jar
jstl-1.2.jar
ognl-3.0.5.jar
struts2-core-2.3.7.jar
xwork-core-2.3.7.jar

【问题讨论】:

  • 您已经发布了两次 web.xml 内容。请发布 struts.xml 文件
  • 欢迎文件保存在哪里?
  • 给出错误日志。我过去有同样的问题,我通过更改 jar 文件解决了。请检查错误日志。我确定 jar 文件有问题。
  • Tomcat 的 catalina.out 中说了什么?最重要的是,在你启动容器(或安装 webapp)之后它会说什么,在你发出请求之后它会说什么?另外,您可能应该记录在您的问题中不起作用的整个请求路径:URL --> struts mapping --> Action class --> 结果模板等

标签: java tomcat struts2 http-status-code-404


【解决方案1】:

我已经修好了,原来我只需要commons-lang jar 到可能lib 目录。

【讨论】:

    【解决方案2】:

    在 web.xml 中尝试以下代码段(在 struts 过滤器用户模式 ​​.action 中)

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>
    

    【讨论】:

    【解决方案3】:

    这是罐子的问题。请检查以下罐子。我有同样的问题,我用下面的罐子解决了。

    commons-fileupload-1.2.1
    commons-io-1.3.2
    commons-logging-1.0.4
    commons-logging-api-1.1
    freemarker-2.3.16
    javassist-3.14.0-GA
    log4j-1.2.16
    ognl-3.0
    struts2-core-2.2.1.1
    xwork-core-2.2.1.1
    

    【讨论】:

      【解决方案4】:

      我有同样的问题,我努力解决了好几个小时,即使我放置了上面提到的合适的罐子。

      我遇到了这个问题,因为 apache tomcat 的 common->lib 文件夹下有太多 jars 文件导致问题。

      所以

      1) 整齐地保存 jars 和依赖关系 2) 检查您的 web-inf 的 lib 文件夹下的 jar 是否存在依赖关系。 3) 检查包含相同类但版本不同的 jar。

      我在卸载tomcat并重新安装时找到了解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-30
        • 2012-10-18
        • 1970-01-01
        • 2020-07-26
        • 1970-01-01
        • 1970-01-01
        • 2017-08-26
        相关资源
        最近更新 更多