struts2中<jsp:forward>跳轉時報404錯誤的問題

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.