hi I am new in Struts2 and want to send parameter from one action to other on redirection
My form is like
<s:form action="saveComment">
<s:push value="ai">
<s:hidden name="id"/>
<table cellpadding="5px">
<tr><td><s:textarea name="description" rows="5" cols="60" theme="simple" />
</td>
<td> <s:submit type="image" src="images/sbt.gif" >
</s:submit>
</td></tr>
</table>
</s:push>
</s:form>
and my struts.xml file is like
<action name="saveComment" method="saveComment" class="com.weaverants.web.AIAction">
<result name="success" type="redirect">
<param name="actionName">displayAI</param>
<param name="aiId">${aiId}</param>
</result>
</action>
<action name="displayAI" method="displayAI" class="com.weaverants.web.AIAction">
<result name="success" >/display_ai.jsp</result>
</action>
You are already passing the parameters in your
saveCommentall you need to declare result type asredirectActionspecifying theactionname as the redirectAction and any other needed parameters. likethe redirected URL generated will be
On the other hand using result type as
redirectmeans response is told to redirect the browser to the specified location (a new request from the client).In this case also action instance, action errors, field errors, etc that was just executed is lost and no longer available and only way to pass parameters is by URL or through sessionSame code as stated for redirectAction can be used
difference between Redirect and actionRedirect is the the first one will use
HttpServletResponse#sendRedirect(String) sendRedirectwhile the later one will be taken care by the struts2 framework by ActionMapper provided by the ActionMapperFactory as is much better to use thanRedirectresult.For passing data beside the URL pattern for these result type you can use