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 | ||||||
---|---|---|---|---|---|---|
| ||||||
<action name="helloName2" class="tutorial.HelloName2"> <result name="success">helloName2-success.jsp</result> <result name="error">helloName-error.jsp</result> </action> |
...
types.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<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 | ||||||
---|---|---|---|---|---|---|
| ||||||
<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> |
...