strust2-result chain

废话不多说直接上代码先

 

 

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>
 

 

你可能感兴趣的:(strust2,chain)