Fork me on GitHub
Edit on GitHub << back to Result types

Redirect Action Result

This result uses the ActionMapper provided by the ActionMapperFactory to redirect the browser to a URL that invokes the specified action and (optional) namespace. This is better than the ServletRedirectResult because it does not require you to encode the URL patterns processed by the ActionMapper in to your struts.xml configuration files. This means you can change your URL patterns at any point and your application will still work. It is strongly recommended that if you are redirecting to another action, you use this result rather than the standard redirect result.

See examples below for an example of how request parameters could be passed in.

See ActionMapper for more details



<package name="public" extends="struts-default">
    <action name="login" class="...">
        <!-- Redirect to another namespace -->
        <result type="redirectAction">
            <param name="actionName">dashboard</param>
            <param name="namespace">/secure</param>
<package name="secure" extends="struts-default" namespace="/secure">
    <-- Redirect to an action in the same namespace -->
    <action name="dashboard" class="...">
        <result name="error" type="redirectAction">error</result>
    <action name="error" class="...">
<package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">
   <!-- Pass parameters (reportType, width and height) -->
   The redirectAction url generated will be :
   <action name="gatherReportInfo" class="...">
      <result name="showReportResult" type="redirectAction">
         <param name="actionName">generateReport</param>
         <param name="namespace">/genReport</param>
         <param name="reportType">pie</param>
         <param name="width">100</param>
         <param name="height">100</param>
         <param name="empty"></param>
         <param name="suppressEmptyParameters">true</param>
         <param name="anchor">summary</param>
    Example of "anchor" param usage in conjunction with "redirectAction" result-type.
    Generated URL: /displayReport.action#SUMMARY
<action name="displayReport">
<action name="financeReport" class="com.mycompany.reports.FinanceReportAction"> 
    <result name="input">/jsp/index.jsp</result>            
    <result name="success" type="redirectAction">
        <param name="actionName">displayReport</param>
        <param name="parse">false</param>
        <param name="anchor">SUMMARY</param>