为什么索引页在 Struts 2 中出现 404 错误
Why index page is giving 404 error in Struts 2
如果我不包含 web.xml
文件,则索引文件可以正常打开,但结果页面 HelloWorld.jsp
会出现 404 错误,而当包含 web.xml
索引页面时会出现 404 错误。
我有 index.jsp
个文件。 localhost:8080
工作正常,但之后出现错误。
看这里:
在第一种情况下,索引文件由服务器上可用的默认 servlet 打开。
在第二种情况下,您使用已弃用的 FilterDispatcher
。
你应该升级Struts到最新版本并使用
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
查看如何编写 Web 应用程序描述符 web.xml。
Simple Example
Configuring web.xml
for the framework is a matter of adding a filter
and filter-mapping.
FilterDispatcher
Example (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>
如果我不包含 web.xml
文件,则索引文件可以正常打开,但结果页面 HelloWorld.jsp
会出现 404 错误,而当包含 web.xml
索引页面时会出现 404 错误。
我有 index.jsp
个文件。 localhost:8080
工作正常,但之后出现错误。
看这里:
在第一种情况下,索引文件由服务器上可用的默认 servlet 打开。
在第二种情况下,您使用已弃用的 FilterDispatcher
。
你应该升级Struts到最新版本并使用
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
查看如何编写 Web 应用程序描述符 web.xml。
Simple Example
Configuring
web.xml
for the framework is a matter of adding a filter and filter-mapping.
FilterDispatcher
Example (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>