Versions Compared

Key

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

...

Code Block
xml
xml
titlestruts.xml
<action name="helloName2Logon" class="tutorial.HelloName2Logon">
  <result name="success">HelloName2-successinput">/tutorial/Logon.jsp</result>
  <result nametype="error">HelloName-error.jsp<redirect-action">HelloWorld</result>
</action>

So farIn the Hello World lesson, 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 struts-default package defines result types for the Result classes provided with the framework. If your package uses a custom result type, you can add it to your package.

...

The Logon mapping uses a different return type for "success" (the default result code). The redirect-action takes the name of an Action as a parameter, and then issues a client-side redirect to the new action. As a result, the URI on the browser's location bar will change.

...

Configuring Global Results

...

Code Block
xml
xml
titlestruts.xml
<package name="default" extends="struts-default">
   <global-results>
      <result name="login" type="redirect-action">login<>Login</result>
      <result name="unauthorized">Unauthorized.jsp<" type="action-chain">Unauthorized</result>
   </global-results>
   <!-- other package declarations -->
</package>
Note
titleGlobal Absolutes

Because global results are searched after local results, you can override any global result mapping by creating a local result mapping of the same name. Results can indicate resources using relative or absolute URIs. Because you may not know the context in which a result is being invoked, it's best to use absolute paths for global results.

...

The framework offers a variety of result types. An Action can select the appropriate result by name, without actually knowing what result type will be rendered. If a result is needed can be used by multiple action mappings, it can be defined once as a global result.

(lightbulb) For more, see Result Types.