开发者

Strut2 - Get Property value in next Action

I am using <s:form action="someAction">

my struts.xml contains

<action name="someAction" 
        class="com.test.testaction.getValue" 
        method="getValuedemo">
    <result name="success" type="redirectAction">demo</result>   
</action> 

while my Action contains

public class getValue extends Actio开发者_如何学PythonnSupport{
    private String userName;

    public String getUserName() {
        return userName;
    }

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

    public String getValuedemo() {
        userName = "tmpUser";
    }
}

My question is how to get userName property in demo.action????? Please help


You can pass userName as a parameter

<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> 

Also add userName getter/setter in the demo action


Values associated with a specific action are per-request. If you set values in an action and then redirect, those values will be lost. If getValue is just redirecting to demo, what is the purpose of the getValue action? Why not just have the userName getter and setter on DemoAction?

Please revise your question to provide more details on what you are trying to do.

Additionally, your action name does not adhere to Java naming conventions for a class, which should start with a capital letter. Additionally, you might want to come up with a better name for the action than GetValue.


First use the chain result type...

<result name="success" type="chain">demo.action</result>

Then read about interceptors so you can avoid using chain, redirect, redirectAction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜