struts2中<jsp:forward>跳转时报404错误的问题

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>
<span style="white-space:pre">	</span><filter-name>struts2</filter-name>
<span style="white-space:pre">	</span><filter-class>
<span style="white-space:pre">	</span>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<span style="white-space:pre">	</span></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>INCLUDE</dispatcher>    //添加对<jsp:include page="xxx.action"/>及其<s:include value="xxx.action"/>支持
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
  </filter-mapping>

解决方法二:

用javascript解决。让请求运行到页面时,接着运行例如以下的代码。发现页面须要重载,然后就又一次发送请求REQUEST,这样当然就会被过滤器所截获到了。


<script language="javascript">location.replace(URL)</script>
解决方法三:
利用html meta,等于也是让页面等待零秒刷新页面。又一次发送请求,达到目的。


<meta http-equiv="refresh" content="0;URL=xxx.action">


转自http://yanln.iteye.com/blog/1602770

http://www.blogjava.net/LaozhonG/archive/2012/02/26/370793.html


posted on 2017-05-11 17:00  ljbguanli  阅读(137)  评论(0编辑  收藏  举报