Struts2 注解中跳转 action
轉自:http://hi.baidu.com/fo_guo/item/71f6b636fec1e8cf382ffa00
在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?
轉載于:https://my.oschina.net/liangzhenghui/blog/183075
總結
以上是生活随笔為你收集整理的Struts2 注解中跳转 action的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: struts2 跳转类型 result
- 下一篇: Python安装与第三方工具——pych