views:

13895

answers:

5

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

+3  A: 

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>
krosenvold
I had a lot of trouble figuring this out: <s:action ...> <s:param ... /> </s:action>does not work in Struts 2.1.8.1. After upgrading to Struts 2.2.1 everything is okay. Haven't found a note on that anywhere.
gre
A: 

Can someone tell me how can I set parameters while calling action from JSP? I have a table in JSP and each row has a corresponding button. On action for button, I want to pass cell value to the action class. Can you please tell me how can I implement this functionality? Thanks a lot.

A: 
<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>
benji
sorry?? should I answer? please, don't spam lookin' for score.
Giancarlo
A: 

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>
Shimit
A: 

@krosenvold - Thanks for the explanations. I have set up an action as follows:

/members/uploadThreadFile.jsp /forum/files.jsp?thread=${thread.id} true true

But the ${thread.id} part is always blank! The action has a field thread, with a public getter and that Thread class also has a public getter for "id". I know for sure that "thread" is not null (since I output a log).

I am running 2.1.6..

Do you have any tips on how to find the problem?

Thanks!

Nic Cottrell