【发布时间】: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
如果我不包含web.xml 文件,则索引文件可以正常打开,但结果页面HelloWorld.jsp 给出404 错误,并且当包含web.xml 索引页面时给出404 错误。
我有index.jsp 文件。 localhost:8080 工作正常,但之后出现错误。
请看这里:
【问题讨论】:
标签: struts2 http-status-code-404 web.xml
在第一种情况下,索引文件由服务器上可用的默认 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>
【讨论】: