strust2-result chain
程序员文章站
2022-07-02 13:25:55
...
废话不多说直接上代码先
public class Test1Action extends ActionSupport{ private String message; @Action("test1") public String test1() { System.out.println(message); return SUCCESS; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
public class Test2Action extends ActionSupport{ private String message; @Action(value="test2",results={@Result(type="chain",name="success",location="test1")}) public String test2() { message="haha"; return SUCCESS; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
当直接运行http://localhost:8080/xxxx/test1.action
打印:null
当运行http://localhost:8080/xxxx/test2.action
打印:haha
官方说明文档:
If you need to copy the properties from your previous Actions in the chain to the current action, you should apply the ChainingInterceptor.
如果你需要在2个action共享参数就可以用这个result类型
如上例子test2.action给message赋值,接着跳转到test1.action。因为result类型是chain,test1.action可以获取在test2.action赋值的message的值
pom.xml
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.2.3</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.2.3</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.8.0.GA</version> </dependency>
推荐阅读
-
贝尔链(Baer Chain):SH-DPOS机制可以让每个人都成为超级
-
域乎创新应用之人力资源篇:H2Chain催生灵活用工快速变革
-
php设计模式 Chain Of Responsibility (职责链模式)
-
责任链模式-Chain of Responsibility(Java实现), 例2
-
责任链模式-Chain of Responsibility(Java实现), 例1
-
The Scope Chain
-
alias, alias_method和alias_method_chain
-
UVA 442 Matrix Chain Multiplication ( stack 应用)
-
PAT-A-1090 Highest Price in Supply Chain【树】
-
PHP Chain 链式编程的应用之错误处理