Strut2 - 在下一个Action中获取Property值

Loh*_*hit 2 struts2

我在用 <s:form action="someAction">

我的struts.xml包含

<action name="someAction" 
        class="com.test.testaction.getValue" 
        method="getValuedemo">
    <result name="success" type="redirectAction">demo</result>   
</action> 
Run Code Online (Sandbox Code Playgroud)

而我的行动包含

public class getValue extends ActionSupport{
    private String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getValuedemo() {
        userName = "tmpUser";
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是如何在demo.action中获取userName属性????? 请帮忙

anu*_*anu 6

您可以将userName作为参数传递

<action name="someAction" class="com.test.testaction.getValue" method="getValuedemo">
    <result name="success" type="redirectAction">
        <param name="actionName">demo</param>
        <param name="userName">${userName}</param>
    </result>
</action> 
Run Code Online (Sandbox Code Playgroud)

还要在演示操作中添加userName getter/setter