Versions Compared

Key

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

When an Action class method completes, it returns a String. The value of the String is used to select a result element. An action mapping will often have a set of results representing different possible outcomes. A standard set of result tokens are defined by the Action interfaceActionSupport base class.

Code Block
java
java
titlePredefined result names
String SUCCESS = "success";
String NONE    = "none";
String ERROR   = "error";
String INPUT   = "input";
String LOGIN   = "login";

...

Code Block
titleSetting a default Result Type
<result-types>
 <result-type name="dispatcher" class="org.apache.strutsstruts2.action2.dispatcher.ServletDispatcherResult" 
  default="true"/>
</result-types>

...

Code Block
xml
xml
titleResult element without defaults
<result name="success" type="dispatcher">
    <param name="location">/thank_youThankYou.jsp</param>
</result>
Code Block
xml
xml
titleA Result element using some defaults
<result>
    <param name="location">/thank_youThankYou.jsp</param>
</result>

The param tag sets a property on the Result object. The most commonly-set property is location, which usually specifies the path to a web resources. The param attribute is another intelligent default.

Code Block
xml
xml
titleResult element using more defaults
<result>/thank_youThankYou.jsp</result>

Mixing results with intelligent defaults with other results makes it easier to see the "critical path".

Code Block
xml
xml
titleMultiple Results
<action name="Hello">
  <result>/pageshello/Hello/Result.jsp</result>
  <result name="error">/pageshello/Hello/Error.jsp</result>
  <result name="input">/pages/Hellohello/Input.jsp</result>
</action>

...

Code Block
xml
xml
titleDefining global results
<global-results>
  <result name="error">/pages/Error.jsp</result>
  <result name="invalid.token">/pages/Error.jsp</result>
  <result name="login" type="redirect-action">Logon!input</result>
</global-results>

...