Adding Global Forwards

 < 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> 

start sidebar

All <forward> sub-elements that are to be made available to the entire application must be nested within a single <global-forwards> element.

end sidebar

Table 15.6 describes the attributes of a <forward> sub-element.

Table 15.6: 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)

start sidebar

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.

end sidebar

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> 

start sidebar

The <forward> sub-element contains no body. It is configured using only its two attributes.

end sidebar



 < Day Day Up > 



Professional Jakarta Struts
Professional Jakarta Struts (Programmer to Programmer)
ISBN: 0764544373
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net