| < Day Day Up > |
|
The <global-forwards> sub-element is used to define n-number of <forward> sub-elements that are available to any Action in the Struts application. It acts as a container for public <forward> sub-elements.
You can use the <forward> sub-element to describe a mapping of a logical name to a context-relative URI path. A forward is used to identify the target of an Action class when it returns its results. This target is most often used to present the results of the Action that names it. The syntax of the <global-forwards> sub-element, including an example nested <forward> element, is:
<global-forwards> <forward name="unique target identifier" path="context-relative path to targetted resource "/> </global-forwards>
All <forward> sub-elements that are to be made available to the entire application must be nested within a single <global-forwards> element.
Table 15.6 describes the attributes of a <forward> sub-element.
Attribute | Description |
---|---|
name | Contains the unique identifier identifying this target. This attribute is used by an Action class to identify its targeted resource. (required) |
path | Specifies the context-relative path of the targeted resource. (required) |
redirect | If set to true, causes the ActionServlet to use the HttpServletResponse.sendRedirect() method, as opposed to the RequestDispatcher.forward() method, when sending the Action results to the targeted resource. The default value is false. (optional) |
If the redirect attribute is set to true, causing the HttpServletResponse. sendRedirect() method to be used, then the values stored in the original HttpServletRequest will be lost.
An example of using the <global-forwards> sub-element appears in the following code snippet:
<global-forwards> <forward name="success" path="/welcome.jsp"/> <forward name="failure" path="/index.jsp"/> </global-forwards>
The <forward> sub-element contains no body. It is configured using only its two attributes.
| < Day Day Up > |
|