<ao:redirect>

Redirects the browser to another location. Stops processing of the containing JSP page.

Does not send redirect when the response has already been committed, but also does not throw any exception; logs FINE-level notice instead.

Important: Redirects inside of standard <jsp:include> tags will be silently lost. Use <ao:include> instead of <jsp:include> to support redirects inside of includes.

Any attribute that has no namespace and begins with param. is added to the href as a URL parameter. The parameter name is the part of the attribute name following param..

When a parameter value is null it is not added. If the value is an Iterable, Iterator, Enumeration, or array, then each non-null element is coerced to String as a separate parameter in iteration order. Otherwise, the value itself is coerced to String for the parameter value.

Nested <ao:param> or <ao:params> tags will add parameters after any provided as attributes.

Due to browser and server URL length limitations for GET requests, it is recommended to not exceed about 2000 characters for URLs, including all parameters. See WWW FAQs: What is the maximum length of a URL?

When redirecting to a resource within the application, such as for a 303 redirect-after-post response, it is recommended to provide the "page" attribute to allow automatic fallback to forward instead of redirect. With this redirect/forward combination, users will have the benefits of redirect-after-post while the system gracefully falls back to request forwarding when the GET request length limit is exceeded.

Tag Information

Tag Class: com.aoapps.taglib.RedirectTag
TagExtraInfo Class: com.aoapps.taglib.RedirectTagTEI
Body Content: scriptless
Display Name: None
Dynamic Attributes: true

Attributes

Name Required Evaluation Type Description
statusCode Yes Runtime String

The status code of redirect performed. Is one of:

  • moved_permanently or 301
  • moved_temporarily or 302
  • see_other or 303 - Hint: Used for redirect-after-post

Because the redirect type has important consequences on search engines and browser caches, the decision should be made for each redirect. Thus, this attribute is required.

href No Runtime String

The destination for the redirect. This should only be provided when either redirecting to an external resource or when the default obtained from "page" is inappropriate. The href is modified in several ways to make things much easier to work with.

A nested <ao:href> tag will override this value.

When not provided as attribute or a nested tag, defaults to the value for "page". This should be a reasonable default except for unusual circumstances.

In order to make relative paths predictable, relative paths are interpreted from the current JSP page.

In order to keep paths app-relative, if starts with a /, the context path will be prepended to the path.

In order to simplify things behind URL mapping schemes, the href is always written starting with '/'. This avoids any need to include any <ao:base> tags.

URL rewriting is performed as needed via HttpServletResponse.encodeURL.

To support paths in different character sets, a Unicode to ASCII URI encoding is performed on every character that is not defined in RFC 3986: Reserved Characters. To avoid ambiguity, any dynamic parameters or anchors in the URL must have been correctly encoded by the caller.

Any directly nested <ao:param> or <ao:params> tag will add parameters to the href.

absolute No Runtime boolean

When true, generates an absolute URL for the Location of the redirect. Defaults to true for compatibility with the requirements prior to RFC 7231: 7.1.2. Location.

canonical No Runtime boolean

When true, will generate a Canonical URL. Canonical URLs should be used where per-user response URL rewriting (such as information added when cookies are disabled) should be avoided. Defaults to false.

addLastModified No Runtime String

If the href represents a local resource, a parameter of "lastModified=#####" may be automatically added with the timestamp of the local resource to the nearest second. May be one of true, false, or auto. Defaults to auto.

In auto mode, last modified stamping may be disabled by the client with the X-com-aoapps-servlet-lastmodified-enabled: false header.

In auto mode, last modified stamping is not performed on Canonical URLs.

page No Runtime String

The page that will be forwarded to when the GET request URL length is exceeded. It is recommended to provide the page for any redirect within a web application, such as 303 redirect-after-post. A nested <ao:page> tag will override this value.

When forward is performed instead of redirect, the original request parameters are hidden. Only the parameters provided in the redirect are passed-on to the target page. Also, any arguments to the current JSP page are not passed-on (see <ao:include>).

Security Note: page must be a trusted value since it can access any resource available via RequestDispatcher. It would be incorrect to use a value that can be manipulated by a client in any way.

Recommend use of <ao:base> on target page to have relative paths interpreted from the forwarded-to page.

When the redirect type is 302 or 303, the cache-control: no-cache header is set on the response to try to best emulate the caching effects the corresponding redirect.

Variables

No Variables Defined.