我们在struts action中如果要进行参数传递,只能通过request,session,或者url参数的方式,但Webwork可以不通过这些,直接用action进行参数传递,这都归功于一个全新的Result Type----chain
首先我们要配置china这个interceptor ref,幸运的是,completeStack中已经包裹了
Action:
package
ch7.example3;
import com.opensymphony.xwork.ActionSupport;
public class TestOne extends ActionSupport ... {
private String username;
public String execute() throws Exception ...{
this.setUsername("gaoxiang");
return SUCCESS;
}
public String getUsername() ...{
return username;
}
public void setUsername(String username) ...{
this.username = username;
}
}
package ch7.example3;
import com.opensymphony.xwork.ActionSupport;
public class TestTwo extends ActionSupport ... {
private String username;
public String execute() throws Exception ...{
System.out.println(this.getUsername());
return NONE;
}
public String getUsername() ...{
return username;
}
public void setUsername(String username) ...{
this.username = username;
}
}
import com.opensymphony.xwork.ActionSupport;
public class TestOne extends ActionSupport ... {
private String username;
public String execute() throws Exception ...{
this.setUsername("gaoxiang");
return SUCCESS;
}
public String getUsername() ...{
return username;
}
public void setUsername(String username) ...{
this.username = username;
}
}
package ch7.example3;
import com.opensymphony.xwork.ActionSupport;
public class TestTwo extends ActionSupport ... {
private String username;
public String execute() throws Exception ...{
System.out.println(this.getUsername());
return NONE;
}
public String getUsername() ...{
return username;
}
public void setUsername(String username) ...{
this.username = username;
}
}
xwork.xml
<
default-interceptor-ref
name
="completeStack"
></
default-interceptor-ref
>
< action name ="testone" class ="ch7.example3.TestOne" >
< result name ="success" type ="chain" > testtwo </ result >
</ action >
< action name ="testtwo" class ="ch7.example3.TestTwo" >
</ action >
< action name ="testone" class ="ch7.example3.TestOne" >
< result name ="success" type ="chain" > testtwo </ result >
</ action >
< action name ="testtwo" class ="ch7.example3.TestTwo" >
</ action >
可以看到记过打印了gaoxiang,这个属性是从TestOne传到TestTwo的,怎样,很方便吧
试想,如果是一个复杂对象,用webwork的这个机制是很容易实现的