Pages Navigation Menu

Coding is much easier than you think

Difference between Action Chaining & Action redirect in Struts 2

 
In Struts 2, sometimes you may want to process another action when one action completes. For example on successfully submitting a form you want to render output from other action.
 
This can be done by two methods
 
1) Action Chaining
2) Action redirect
 
Action chaining in Struts 2
 
** UPDATE: Struts 2 Complete tutorial now available here.
 
Difference between Action redirect & Action Chaining:
 
Difference between Action Chaining & Action redirect is, Action Redirect starts from scratch, it is like you called the other action class for the first time while Action Chaining keeps the values of the first Action class on the value stack and adds the variables of the new action. Look at the example below to understand the above concepts.
 
Action Chaining:
 

<package name="default" extends="struts-default">
    <action name="Register" class="com.simplecode.action.RegisterAction">
	<result name="success" type="chain">dbAction</result>
    </action>
    <action name="dbAction" class="com.simplecode.action.DataBaseAction">
	<result name="success">/success.jsp</result>
    </action>
</package>

 
Action redirect:
 

<package name="default" extends="struts-default">
    <action name="Register" class="com.simplecode.action.RegisterAction">
	<result name="success" type="redirect">dbAction</result>
    </action>
    <action name="dbAction" class="com.simplecode.action.DataBaseAction">
	<result name="success">/success.jsp</result>
    </action>
</package>

 

About Mohaideen Jamil


Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

  • Nguyễn Quang Hải

    how about Difference
    between Action Chaining & Redirect Action ?how about Difference between Action Chaining & Redirect Action ?

    (type=”redirectAction” Vs type=”chain”)

  • Anh

    Your article extremely nice! Thanks a lot

    • http://www.simplecodestuffs.com Mohaideen Jamil

      Thankyou for the feedback!

  • Ajit

    Hi,

    This article of yours helped me a lot.
    Thank you so much.

    • http://www.simplecodestuffs.com Mohaideen Jamil

      Most welcome:)