Struts2 註解中跳轉 action

在xml中跳轉action我想大家都是會的,那麼註解中跳轉其實也很類似,廢話不多說,直接上代碼:

@Results({
  @Result(name = "toEditFollow", type = "redirect", location = "follow!toEditFollow?baseId=${baseInfo.baseId}&&flag=${flag}")})

 

 public String updateOutTime() throws ParseException {

//相關操作後
   return "toAddFollow";
 }

這裏面要注意的幾點是:

1、chain是不可以跳轉其他action中的方法的,必須使用redirect

2、使用redirect要丟失之前的各種參數,需要重新傳遞,傳遞時可以使用EL表達式

 

附上xml中返回值的類型,這和註解中其實是一樣的

 

chain

用來處理Action鏈,被跳轉的action中仍能獲取上個頁面的值,如request信息。 

com.opensymphony.xwork2.ActionChainResult 

 

 dispatcher 

用來轉向頁面,通常處理JSP 

org.apache.struts2.dispatcher.ServletDispatcherResult 

 

redirect

重定向到一個URL?,被跳轉的頁面中丟失傳遞的信息,如request 

org.apache.struts2.dispatcher.ServletRedirectResult 


redirectAction 

重定向到一個Action?,跳轉的頁面中丟失傳遞的信息,如request 

org.apache.struts2.dispatcher.ServletActionRedirectResult 

 

redirect-action 

重定向到一個Action?,跳轉的頁面中丟失傳遞的信息,如request 

org.apache.struts2.dispatcher.ServletActionRedirectResult?

 

//以下不常用
freemaker 

處理FreeMarker模板 

org.apache.struts2.views.freemarker.FreemarkerResult 

 httpheader 

控制特殊HTTP行爲的結果類型 

org.apache.struts2.dispatcher.HttpHeaderResult 
stream?

向瀏覽器發送InputSream對象,通常用來處理文件下載,還可用於返回AJAX數據 

org.apache.struts2.dispatcher.StreamResult 

 velocity 

處理Velocity模板 

org.apache.struts2.dispatcher.VelocityResult 

 xslt 

處理XML/XLST模板 

org.apache.struts2.views.xslt.XSLTResult 

 plainText 

顯示原始文件內容,例如文件源代碼 

org.apache.struts2.dispatcher.PlainTextResult 


 plaintext 

顯示原始文件內容,例如文件源代碼 

org.apache.struts2.dispatcher.PlainTextResult?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章