Versions Compared

Key

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

...

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

So far, our results have used the default type, Dispatcher. The Dispatcher forwards to another web resource. Other kinds of views can be used by specifying a different result type.

Configuring Result Types

The actionstruts-default package defines result types for the Results Result classes provided with the framework. If your package uses a custom result type, you can add it to your package.types.

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

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

      <action name="imageImage" class="tutorial.ImageActionImage">
        <result name="success" type="imageImage"/>
     </action>
   </package>
</xwork>

...

It's not unusual for mappings to share a need for the same result. For example, if your application is securedsecure, 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
titlestruts.xml
<package name="default" extends="webworkstruts-default">
   <global-results>
      <result name="login" type="redirect-action">login</result>
      <result name="unauthorized">/unauthorized>Unauthorized.jsp</result>
   </global-results>
   <!-- other package declarations -->
</package>

...