Home

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

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

The Presentation Location Tags

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

Using forward

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

Using redirect

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.

Previous
Next