Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor edits.

Sometimes there is a need to redirect from one action to another, but you do not know the exact url URL or that the destination url URL requires parameters that are only known in runtimeat run-time.

Struts 2 gives you offers an easy to use solution for that problem.

Parameters in action result definitions

Code Block
xml
xml
<struts>
....
   <package name="somePackage" namespace="/myNamespace" extends="struts-default">
      <action name="myAction" class="com.project.MyAction">
         <result name="success" type="redirectAction">otherAction?id=${id}</result>
         <result name="back" type="redirect">${redirectURL}</result>
      </action>

      <action name="otherAction" class="com.project.MyOtherAction">
         ...
      </action>      
   </package>
....
</struts>

The only requirement is to declare the necessary properties in your action, in this case com.project.MyAction should define properties id and redirectURL with standard accessor methods.

...