JuanDeLosMuertos
JuanDeLosMuertos

Reputation: 4620

Struts2 parameters between actions

I have to pass some parameter from an action to another action,for example to keep trace of an event.

What is the best way to do that?

I would not use session parameters. Thanks

Upvotes: 7

Views: 54112

Answers (5)

Sarathy
Sarathy

Reputation: 11

Actually you are going to pass your one action parameter value from one action to another action.

simply include bean variable with same name. which parameter you are going to receive on action(receiver action).

<action name="ForwardAction" class="...">
       <result name="success" type="chain">ReceiverAction</result>
</action>

ForwardAction parameter will be forwarded to ReceiverAction. you can use it. but include same bean name in both actions.

if you are going to receive userid in receiveaction means.,

This should be in both actions.,

private int userid;

public void setUserid(int id){
     this.userid = userid;
}

public int getUserid(){
     return userid;
}

Upvotes: 1

Jackie
Jackie

Reputation: 25969

actually, the scope and servletConfig interceptor can be utilized in struts2, to automatic pop the action context parameters, (request/session, etc)

Upvotes: 0

user177863
user177863

Reputation:

<td>
   <s:url id="url" action="Logging">
      <s:param name="m_userNameInAction"><s:property value="m_userNameInForm"/></s:param>
    </s:url>
    <s:a href="%{url}">English</s:a>
</td>

Upvotes: 1

Shimit
Shimit

Reputation: 11

Use url tag in the struts core tags, sample is given below:

                <s:url var="idurl" action="EditEnterprise">
                    <s:param name="enterpriseId">
                        <s:property value="enterpriseId" />
                    </s:param>
                </s:url> 

Upvotes: 1

krosenvold
krosenvold

Reputation: 77171

Assuming you are serverside within one action and wishing to invoke another action with some parameters.

You can use the s:action tag to invoke another action, possibly with additional/other parameters than the original action:

    <s:action name="myAction"  ignoreContextParams="true" executeResult="true">
        <s:param name="foo" value="bar"/>
    </s:action>

You can also use a standard struts-xml result type with a parameter:

<result name="success" type="redirect" >
      <param name="location">foo.jsp?foo=${bar}</param>
      <param name="parse">true</param>
      <param name="encode">true</param>
 </result>

If you want a client side redirect you have to send an url back to the client with the proper parameters, and maybe use some javascript to go there.

        <s:url action="myAction" >
            <s:param name="foo" value="bar"/>
        </s:url>

Upvotes: 11

Related Questions