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">  
原文地址:https://www.cnblogs.com/wangkang0320/p/8675746.html