struts2中,在使用 convention 插件的情况下,如何使用 “chain” 这个result
来源:互联网 发布:手机桌面天气预报软件 编辑:程序博客网 时间:2024/06/05 03:49
执行完一个Action之后,一般就是跳转至某个JSP页面之类的,但在某些情况下,也有执行完一个Action之后需要跳转至另一个Action继续执行。
比如,使用 addUser 这个Action 新增一个用户之后,我们可能需要使用 userList 这个Action跳转至用户一览画面。
上面这种需求,在使用xml格式的配置文件时,是很容易配置的。所以,此处就不列出了。
此处想说一下,在使用 convention 插件的情况,如何通过 注解来实现。
基于注解方式,又分为两种情况:
第一种: 在 method 级别使用了 @Action 注解来指明该 method 是用来处理哪个 action 的,
这种情况下的写法,请参见: http://jis225.blog.163.com/blog/static/57329156201152881839409/
第二种: 不使用@Action注解去标注 method, 而是通过以 “!” 的方式去动态调用一个 method。下面以实例来说明一下:
@Results({ @Result(name = "listMajorKind", location = "/jsp/kind/major/list.jsp") })public class KindAction { public String queryMajorKind() { return "listMajorKind"; } public String addMajorKind() { return "queryMajorKind"; }}
对于上面这段代码 ,在使用 convention 的前提下,我们知道:
“kind!queryMajorKind” 这个URL最终会跳转至 “/jsp/kind/major/list.jsp” 页面。
那对于“kind!addMajorKind” 这个URL,如果我也想让其最终跳转至上面这个JSP页面的话,应该怎么Result呢?
我先把配置贴出来吧,然后对着代码解释一下:
@Results({ @Result(name = "listMajorKind", location = "/jsp/kind/major/list.jsp"), @Result(name = "queryMajorKind", type = "chain", params = { "namespace", "/", "actionName", "kind", "method", "queryMajorKind" }) })public class KindAction { public String queryMajorKind() { return "listMajorKind"; } public String addMajorKind() { return "queryMajorKind"; }}
细心的朋友已经注意到了,我多加了一行:
@Result(name = "queryMajorKind", type = "chain", params = { "namespace", "/", "actionName", "kind", "method", "queryMajorKind" })
这个配置的就跟 XML 格式的配置其实是一样的,其中:
- “chain” 指定了这个 result的类型是去调用是另一个 action
- 那么,这个action它的名字是什么,它的命名空间、动态调用的方法又是什么?该怎么设置呢?答案就是通过 params 这个参数来设置。对于params,可以看一下如下的API说明:
The parameters passed to the result. This is a list of strings that form a name/value pair chain since creating a Map for annotations is not possible. An example would be: {"key", "value", "key2", "value2"}.
那么,我们又如何知道应该往params中放入哪些参数呢?这个时候,就要去看代码了。
我们知道“chain”类型的result,它的处理类是“com.opensymphony.xwork2.ActionChainResult”,这个类的API说明里道出它需要哪些参数:
This result invokes an entire other action, complete with it's own interceptor stack and result. This result type takes the following parameters: ・actionName (default) - the name of the action that will be chained to ・namespace - used to determine which namespace the Action is in that we're chaining. If ・namespace is null, this defaults to the current namespace ・method - used to specify another method on target action to be invoked. If null, this defaults to execute method ・skipActions - (optional) the list of comma separated action names for the actions that could be chained to
看到这,应该明白上面的配置了吧。
- struts2中,在使用 convention 插件的情况下,如何使用 “chain” 这个result
- struts2 convention result 使用chain
- Struts2中 Convention插件的使用
- Struts2 Convention插件的使用
- Struts2 Convention插件的使用
- struts2 Convention 插件使用
- Struts2使用 -- Convention插件
- Struts2的convention插件,在步骤中使用Action注解跳转到其他jsp页面
- 使用struts2 convention插件遇到的问题
- struts2 convention插件的使用(一)
- Struts2使用26 -- Convention插件
- Struts2 使用26 -- Convention插件
- Convention插件的使用
- Convention插件的使用
- struts2中result的使用
- struts2 中dispatcher、redirect和chain三种result type的使用区别
- struts2 中dispatcher、redirect和chain三种result type的使用区别
- struts2采用convention-plugin实现零配置,Struts2 Convention插件的使用
- 设备协安装程序
- Web项目中 Tomcat 与 资源文件的一些处理
- android初接触之activity1
- 最牛逼的回调框架,只需简单异步就能享受到牛逼的回调,EventBus
- cxf发布webservice及客户端调用
- struts2中,在使用 convention 插件的情况下,如何使用 “chain” 这个result
- lr 录制脚本 打不开 IE浏览器
- 学习设计模式原则之依赖倒置原则,代码笔记
- jdk 1.7 安装 centos6.4-64位
- Boost源码学习十一[并发编程](3)
- mysql中的数据同步到elasticsearch
- Java六种排序算法
- 内核驱动中改写寄存器值
- apk打包中程序包R不存在的问题