我們在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;
}
}
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 >
可以看到記過列印了gaoxiang,這個屬性是從TestOne傳到TestTwo的,怎樣,很友善吧
試想,如果是一個複雜對象,用webwork的這個機制是很容易實作的