|Apache Struts 2 Documentation > Home > Tutorials > Bootstrap > Selecting Results|
In the Coding Actions lesson, we created a Logon class that tests for input. In the Selecting Results lesson, we act on the outcome of that test.
After the Action processes a request, a result is selected to provide the response. A result may simply forward to an HTML page, a JavaServer page, a FreeMaker or Velocity template, or the result might construct a PDF or some other complex report (like JasperReports). 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.
In the Hello World lesson, our results 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.
The Logon mapping uses a different return type for "success" (the default result code). The redirectAction result type takes the name of an Action (as configured in the struts.xml file) 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.
As we develop web applications, we often need to make forward references – we need to refer to an action we haven't written yet. For example, in the first part of the lesson, the next step is to open the "Menu" page. If we Logon successfully, there will be no where to go, since "Menu" doesn't exist yet.
One way to work around this problem is to create a stub "Menu" page.
|If you are not using wildcards, another way to inject a "missing" page would be to specify a <default-action-ref> element|
If you are building an application page by page, it can be worthwhile to setup a standard "Missing" page, and then include it from your stubs.
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.
For more, see Result Types in the Core Developers Guide.