Struts2 options between actions

I need to pass some parameter from an action to another action, for example, to track an event.

What is the best way to do this?

I would not use session parameters. Thanks

+7
java parameters jsp struts2 action
source share
5 answers

Assuming that you are a server within one action and want to call another action with some parameters.

You can use the s: action tag to invoke another action, possibly with additional / different 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 the standard struts-xml result type with the 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 to redirect the client side, you need to send the URL back to the client with the appropriate parameters and, possibly, use some kind of javascript to get there.

  <s:url action="myAction" > <s:param name="foo" value="bar"/> </s:url> 
+11
source share
 <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> 
+1
source share

Use url tag in core struts tags, sample below:

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

In fact, you are going to transfer your meaning of one action from one action to another action.

just include the bean variable with the same name. what parameter you are going to receive by action (receiver action).

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

The ForwardAction parameter will be redirected to ReceiverAction. you can use it. but include both bean names in both actions.

if you intend to receive the user ID in the means of receipt.

It should be in both actions.,

 private int userid; public void setUserid(int id){ this.userid = userid; } public int getUserid(){ return userid; } 
+1
source share

In fact, the scope and servletConfig interceptor can be used in struts2 to automatically add action context parameters (request / session, etc.).

0
source share

All Articles