Struts2 注解中跳转 action

来源:互联网 发布:法兰克编程教学 编辑:程序博客网 时间:2024/05/18 02:29
在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?

0 0
原创粉丝点击