码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-07-22 14:25:44      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:jspforward   struts2 basepath   

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>  <span style="white-space:pre">	</span>
  <span style="white-space:pre">	</span><filter-name>struts2</filter-name>
  <span style="white-space:pre">	</span><url-pattern>/*</url-pattern>
  </filter-mapping>


修改为:
  <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>  <span style="white-space:pre">	</span>
  <span style="white-space:pre">	</span><filter-name>struts2</filter-name>
  <span style="white-space:pre">	</span><url-pattern>/*</url-pattern>
<span style="white-space:pre">	</span><dispatcher>INCLUDE</dispatcher>    //增加对<jsp:include page="xxx.action"/>及其<s:include value="xxx.action"/>支持
  <span style="white-space:pre">	</span><dispatcher>REQUEST</dispatcher>
  <span style="white-space:pre">	</span><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


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

标签:jspforward   struts2 basepath   

原文地址:http://blog.csdn.net/shanhuhau/article/details/38036529

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!