Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

After the Action processes the request, a result is selected to provide the response. A result may simply forward to a HTML page, or a JavaServer page, a FreeMaker or Velocity template, or the result might construct a PDF or some other complex report. There may be multiple results available to an action mapping. To indicate which one to select, the Action class returns a name corresponding to the appropriate result.

Code Block
xml
xml
titleactionstruts.xml
<action name="helloName2" class="tutorial.HelloName2">
       <result name="success">helloName2-success.jsp</result>
       <result name="error">helloName-error.jsp</result>
     </action>

...

types.

Code Block
xml
xml
titleactionstruts.xml
<xwork>
   <include name="actionstruts-default.xml"/>
   <package name="default" extends="actionstruts-default">

      <result-types>
        <result-type name="image" class="tutorial.ImageResult" />
      </result-types>

      <action name="image" class="tutorial.ImageAction">
        <result name="success" type="image"/>
     </action>
   </package>
</xwork>

...

It's not unusual for mappings to share a need for the same result. For example, if your application is secured, then many mappings might need to return "login" if the security check fails. Rather than define a common result in every action mapping, the framework lets you define global results.

Code Block
xml
xml
titleactionstruts.xml
<package name="default" extends="webwork-default">
   <global-results>
      <result name="login" type="redirect-action">login</result>
      <result name="unauthorized">/unauthorized.jsp</result>
   </global-results>
   <!-- other package declarations -->
</package>

...