Struts2 中 Result的 Chain Result,Redirect Action Result,Redirect Result 三者之间的区别


Chain Result:
这个result调用另外的一个action,连接自己的拦截器栈和result。
  • actionName (默认) - 被调用的action的名字
  • namespace - 被调用的action的名称空间. 如果名称空间为空,这默认为当前名称空间
  • method - 用于指定目标action的另一个方法被调用. 如果空,默认为excute方法
Redirect Action Result:
这个Result使用ActionMapperFactory提供的ActionMapper来重定位浏览器的URL来调用指定的action和(可选的)namespace. 这个Result比ServletRedirectResult要好.因为你不需要把URL编码成xwork.xml中配置的ActionMapper提供的模式. 这就是说你可以在任意点上改变URL模式而不会影响你的应用程序. 因此强烈推荐使用这个Result而不是标准的redirect result来解决重定位到某个action的情况.
  • ActionName (默认) - 重定位到的action名
  • namespace - action的名称空间. 如果为null,则为当前名称空间

Redirect Result

调用{@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 阅读(2634) 评论(0)  编辑  收藏 所属分类: Struts2


只有注册用户登录后才能发表评论。


网站导航:
 
<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

导航

统计

公告

我曾经听到这么一个故事: 一个年轻的程序员问一个老程序员(一个比较牛逼的公司的CTO) 年轻程序员: 你为什么这么牛X., 就好像没有你不会的。老程序员: 积累的。年轻程序员: 怎么才能积累到您的程度呢。我每天都在积累。但是似乎都没有感觉到进步。老程序员: 我从20岁开始做到了一件事情,直到今天,而且尽可能地保证不间断。年轻程序员: 到底是什么? 老程序员: 我每天保证自己有2个小时在学习新的东西。

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

相册

收藏夹

Java Website

java技术博客

搜索

最新评论

阅读排行榜

评论排行榜