| This Chapter | |
| - | Chapter 9: The Logic Tag Library |
| - | The Value Comparison Tags |
| - | The Substring Matching Tags |
| - | The Presentation Location Tags |
| - | The Collection Utility Tag |
| - | Summary |
There are two presentation location tags, forward and redirect, described in Table 9.3.
| Tag | Description | JSTL Equivalent |
|---|---|---|
| forward | Forwards the user to the specified resource. | |
| redirect | Redirects the user to the specified resource. | c:redirect |
Table 9.3: The presentation location tags
The forward tag forwards the user to the specified location. This tag has an attribute, name, which is a required attribute that specifies the logical name of a forward destination, defined in the Struts configuration file.
Here is an example of the forward tag.
<logic:forward name="displayLoginForm"/>
The redirect tag composes a hyperlink and redirects the browser to resource specified by the hyperlink, either external or internal. It supports URL rewriting so that the session identifier will be included in the target URL. Its attributes are given in Table 9.4.
| Attribute | Description | Possible Value(s) |
|---|---|---|
| action | Specifies a destination Struts action | string |
| anchor | Optional anchor tag (#xxx) to be added to the generated hyperlink. Do not include the # character. | string |
| forward | The logical name of a forward element within the global-forwards element in the Struts configuration file, that contains the actual content-relative URI of the destination of this redirect. | string |
| href | The destination URL to which the user will be redirected. | string |
| name | A scoped variable that references a Map containing query parameters of the generated hyperlink (if the property attribute is not specified), or a scoped variable whose property getter returns a Map containing query parameters (if property is specified). | string |
| page | The module-relative path (beginning with a "/" character) to which this hyperlink will transfer control if activated. | string |
| paramId | The name of the request parameter that will be dynamically added to the generated hyperlink. The corresponding value is defined by the paramName and paramProperty attributes. | string |
| paramName | A scoped variable referencing a String containing the value for the request parameter specified by the paramId attribute (if the paramProperty attribute is not specified), or a scoped variable referencing a scoped object whose property getter returns a String containing the request parameter value (if paramProperty is specified). | string |
| paramProperty | The property of the scoped object specified by the paramName attribute, whose return value must be a String containing the value of the request parameter (named by the paramId attribute). | string |
| paramScope | The scope of the scoped object specified by the paramName attribute. If not specified, all scopes are searched. | page, request, session, or application |
| property | The property of the scoped object specified by the name attribute, whose return value must be a java.util.Map containing the query parameters to be added to the hyperlink. | string |
| scope | The scope of the scoped object specified by the name attribute. If not specified, all scopes are searched. | page, request, session, or application |
| transaction | A value of true indicates that any current transaction control token will be included in the generated hyperlink, so that it will pass an isTokenValid() test in the destination action. | false or true |
| useLocalEncoding | A value of true sets the characterEncoding header of the HTTP response with the value of LocalCharacterEncoding, instead of UTF-8. | false or true |
Table 9.4: The redirect tag’s attributes
The use of the redirect tag is similar to that of the HTML Tag Library’s link tag, discussed in Chapter 3. The generated hyperlink can have zero, one, or many request parameters. The attributes of the redirect tag are also similar to those of the link tag. Consult the section that discusses the link tag to understand how to use the attributes to control the generated hyperlink.