【问题标题】:Why index page is giving 404 error in Struts 2为什么索引页面在 Struts 2 中给出 404 错误
【发布时间】:2016-03-15 03:37:31
【问题描述】:

如果我不包含web.xml 文件,则索引文件可以正常打开,但结果页面HelloWorld.jsp 给出404 错误,并且当包含web.xml 索引页面时给出404 错误。

我有index.jsp 文件。 localhost:8080 工作正常,但之后出现错误。

请看这里:


【问题讨论】:

标签: struts2 http-status-code-404 web.xml


【解决方案1】:

在第一种情况下,索引文件由服务器上可用的默认 servlet 打开。

在第二种情况下,您使用已弃用的FilterDispatcher

您应该将 Struts 升级到最新版本并使用

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

了解如何编写 Web 应用程序描述符 web.xml

简单示例

为框架配置web.xml 就是添加一个过滤器 和过滤器映射。

FilterDispatcher 示例 (web.xml):

<web-app id="WebApp_9" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 2013-12-03
    • 2013-04-18
    • 1970-01-01
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多