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 |
---|
title | Predefined result names |
---|
|
String SUCCESS = "success";
String NONE = "none";
String ERROR = "error";
String INPUT = "input";
String LOGIN = "login";
|
...
Code Block |
---|
title | Setting 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 |
---|
title | Result element without defaults |
---|
|
<result name="success" type="dispatcher">
<param name="location">/thank_youThankYou.jsp</param>
</result>
|
Code Block |
---|
| xml |
---|
| xml |
---|
title | A 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 |
---|
title | Result 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 |
---|
title | Multiple 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 |
---|
title | Defining 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>
|
...