Struts2 中 Result的 Chain Result,Redirect Action Result,Redirect Result 三者之間的區別
Chain Result:
這個result調用另外的一個action,連接自己的攔截器棧和result。
- actionName (默認) - 被調用的action的名字
- namespace - 被調用的action的名稱空間. 如果名稱空間為空,這默認為當前名稱空間
- method - 用于指定目標action的另一個方法被調用. 如果空,默認為excute方法
這個Result使用ActionMapperFactory提供的ActionMapper來重定位瀏覽器的URL來調用指定的action和(可選的)namespace. 這個Result比ServletRedirectResult要好.因為你不需要把URL編碼成xwork.xml中配置的ActionMapper提供的模式. 這就是說你可以在任意點上改變URL模式而不會影響你的應用程序. 因此強烈推薦使用這個Result而不是標準的redirect result來解決重定位到某個action的情況.
- ActionName (默認) - 重定位到的action名
- namespace - action的名稱空間. 如果為null,則為當前名稱空間
調用{@link HttpServletResponse#sendRedirect(String) sendRedirect}方法來轉到指定的位置. HTTP響應被告知使瀏覽器直接跳轉到指定的位置(產生客戶端的一個新請求). 這樣做的結果會使剛剛執行的action(包括action實例,action中的錯誤消息等)丟失, 不再可用. 這是因為action是建立在單線程模型基礎上的. 傳遞數據的唯一方式就是通過Session或者可以為Ognl表達式的web參數(url?name=value)
- location (默認) - action執行后跳轉的地址.
- parse - 默認為true. 如果設置為false, location參數不會被當作Ognl表達式解析.
<result name="success" type="redirect">/displayCart.action?userId=${userId}</result>
------------
Chain result type is used for Action Chaining which means that the source result invokes an entire other action, complete with it's own interceptor stack and result.
Redirect Action result type is used to redirect to another Action which means making your source Action, after it has successfully executed, result in a redirect.
As a rule, Action Chaining is not recommended. Redirect Result or the Redirect Action Result is preferred over Chain Result.
posted on 2009-04-26 23:04 luofeng225 閱讀(2648) 評論(0) 編輯 收藏 所屬分類: Struts2