標籤: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錯誤的問題