问题如下:
- index.jsp页面:
- <jsp:forward page="show.action"></jsp:forward>
- 在struts.xml配置如下:
- <package name="struts2" extends="struts-dafult">
- <action name="show" class="action.ShowAction">
- <result name="showinfo">/showinfo.jsp</result>
- </action>
- </package>
- 在运行时出现404错误(找不到 show.action )
问题原因:
struts2拦截器把forward这个请求拦截了。
解决方法:
修改web.xml文件
- <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>
- 修改为:
- <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>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- </filter-mapping>
本文详细解释了在使用Struts2框架时,由于jsp页面跳转配置不当导致的404错误问题,并提供了通过修改web.xml文件来解决该问题的具体步骤。


6413

被折叠的 条评论
为什么被折叠?



