Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 812
Giancarlo Avatar asked Dec 17 '08 09:12

Giancarlo


2 Answers

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>
like image 160
krosenvold Avatar answered Sep 19 '22 07:09

krosenvold


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> 
like image 29
Shimit Avatar answered Sep 19 '22 07:09

Shimit