日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

struts2 跳转类型 result type=chain、dispatcher、redirect

發布時間:2025/3/15 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 struts2 跳转类型 result type=chain、dispatcher、redirect 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉自:

dispatcher 為默認跳轉類型,用于返回一個視圖資源(如:jsp)
Xml代碼 :

<result name="success">/main.jsp</result>
<result name="success">/main.jsp</result>
以上寫法使用了兩個默認,其完整的寫法為:?
<result name="success" type="dispatcher">
??????? <param name="location">/maini.jsp</param>
</result>

用于頁面轉發,頁面跳轉過程一直是同一個線程,Action中的數據一直保存在。
location只能是頁面,不能是另一個action(可用type="chain"解決)。

?

redirect 類型用于重定向到一個頁面,另一個action或一個網址。
Xml代碼:

<result name="success" type="redirect">aaa.jsp</result>
<result name="success" type="redirect">bbb.action</result>
<result name="success" type="redirect">www.baidu.com</result>

缺點:redirect把一個http返回碼(SUCCESS)以及返回的頁面位置一起重新發給web服務器,容納后由web服務器產生一個新的HTTP請求,就會產生一個新的線程,保存在原來Action執行的線程中的數據就無法訪問。
所以,result需要包含Action的數據,那么redirect不是一個可行的辦法。因為新的HTTP請求時在Servlet容器的新的線程中處理的,ActionContext中的所有狀態都不會存在。

處理方法:

(方法一):
<result name="topic" type="redirect">/topicAction!findTopics.do?topicId=${topicId}</result>
(方法二):
<result name="topic" type="redirect-action">
<param name="actionName">findTopics</param>
<param name="topicId">${topicId}</param>
</result>

?

redirect-action 結果類型使用ActionMapperFactory提供的ActionMapper來重定向請求到另外一個action
Xml代碼:

<result name="err" type="redirect-action">
??? <param name="actionName">重定向的Action名</param>
???? <param name="namespace">重定向Action所在的名字空間</param>
</result>
redirect和redirect-action兩種結果類型在使用上其實并沒有什么區別,只是寫法不同而已。

?

chain 用于把相關的幾個action連接起來,共同完成一個功能。
Xml代碼:

<action name="step1" class="test.Step1Action">
???? <result name="success" type="chain">step2.action</result>
</action>
<action name="step2" class="test.Step2Action">
<result name="success">finish.jsp</result>
</action>
處于chain中的action屬于同一個http請求,共享一個ActionContext


plaintextj 結果類型用于直接在頁面上顯示源代碼

Xml代碼:

<result name="err" type="plaintext">
??? <param name="location">具體的位置</param>
??? <param name="charSet">字符規范(如GBK)</param>
</result>

轉載于:https://my.oschina.net/liangzhenghui/blog/183064

總結

以上是生活随笔為你收集整理的struts2 跳转类型 result type=chain、dispatcher、redirect的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。