webwork chain类型的result

来源:互联网 发布:淘宝app下载ipad版 编辑:程序博客网 时间:2024/05/17 01:51

 webwork chain类型的result
 

我们在struts action中如果要进行参数传递,只能通过request,session,或者url参数的方式,但Webwork可以不通过这些,直接用action进行参数传递,这都归功于一个全新的Result Type----chain

Chain类型的Result可以复制action链中的前一个action的属性到后一个action的属性(这个属性必须在两个action中定义,并且有get,set方法)这一切过程的实现,将使用一个叫chain的interceptor完成,看以下代码


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="defaultStack "></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">

  <interceptor-ref name="chain" />

<interceptor-ref name="defaultStack" />

</action>

可以看到打印了gaoxiang,这个属性是从TestOne传到TestTwo的,怎样,很方便吧

试想,如果是一个复杂对象,用webwork的这个机制是很容易实现的