java.lang.Object | |||||
↳ | org.springframework.context.support.ApplicationObjectSupport | ||||
↳ | org.springframework.web.context.support.WebApplicationObjectSupport | ||||
↳ | org.springframework.web.servlet.view.AbstractView | ||||
↳ | org.springframework.web.servlet.view.AbstractUrlBasedView | ||||
↳ | org.springframework.web.servlet.view.RedirectView |
View that redirects to an absolute, context relative, or current request
relative URL. By default all primitive model attributes (or collections
thereof) are exposed as HTTP query parameters, but this behavior can be changed
by overriding the isEligibleProperty(String, Object)
method.
A URL for this view is supposed to be a HTTP redirect URL, i.e.
suitable for HttpServletResponse's sendRedirect
method, which
is what actually does the redirect if the HTTP 1.0 flag is on, or via sending
back an HTTP 303 code - if the HTTP 1.0 compatibility flag is off.
Note that while the default value for the "contextRelative" flag is off, you will probably want to almost always set it to true. With the flag off, URLs starting with "/" are considered relative to the web server root, while with the flag on, they are considered relative to the web application root. Since most web applications will never know or care what their context path actually is, they are much better off setting this flag to true, and submitting paths which are to be considered relative to the web application root.
NOTE when using this redirect view in a Portlet environment: Make sure
that your controller respects the Portlet sendRedirect
constraints.
When e.g. using SimpleFormController
,
make sure to set your controller's
"redirectAction"
property to "true", in order to make the controller base class behave accordingly.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractView
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From interface
org.springframework.web.servlet.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor for use as a bean.
| |||||||||||
Create a new RedirectView with the given URL.
| |||||||||||
Create a new RedirectView with the given URL.
| |||||||||||
Create a new RedirectView with the given URL.
| |||||||||||
Create a new RedirectView with the given URL.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Set whether to interpret a given URL that starts with a slash ("/")
as relative to the current ServletContext, i.e.
| |||||||||||
Set the encoding scheme for this view.
| |||||||||||
Set the
exposeModelAttributes flag which denotes whether
or not model attributes should be exposed as HTTP query parameters. | |||||||||||
Set whether to stay compatible with HTTP 1.0 clients.
| |||||||||||
Set the status code for this view.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Append query properties to the redirect URL.
| |||||||||||
Determines the status code to use for HTTP 1.1 compatible requests.
| |||||||||||
Determine whether the given model element should be exposed
as a query property.
| |||||||||||
Determine whether the given model element value is eligible for exposure.
| |||||||||||
Determine name-value pairs for query strings, which will be stringified,
URL-encoded and formatted by
appendQueryProperties(StringBuilder, Map . | |||||||||||
Convert model to request parameters and redirect to the given URL.
| |||||||||||
Send a redirect back to the HTTP client
| |||||||||||
URL-encode the given input String with the given encoding scheme.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractUrlBasedView
| |||||||||||
From class
org.springframework.web.servlet.view.AbstractView
| |||||||||||
From class
org.springframework.web.context.support.WebApplicationObjectSupport
| |||||||||||
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanNameAware
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.context.ApplicationContextAware
| |||||||||||
From interface
org.springframework.web.context.ServletContextAware
| |||||||||||
From interface
org.springframework.web.servlet.View
|
Constructor for use as a bean.
Create a new RedirectView with the given URL.
The given URL will be considered as relative to the web server, not as relative to the current ServletContext.
url | the URL to redirect to |
---|
Create a new RedirectView with the given URL.
url | the URL to redirect to |
---|---|
contextRelative | whether to interpret the given URL as relative to the current ServletContext |
Create a new RedirectView with the given URL.
url | the URL to redirect to |
---|---|
contextRelative | whether to interpret the given URL as relative to the current ServletContext |
http10Compatible | whether to stay compatible with HTTP 1.0 clients |
Create a new RedirectView with the given URL.
url | the URL to redirect to |
---|---|
contextRelative | whether to interpret the given URL as relative to the current ServletContext |
http10Compatible | whether to stay compatible with HTTP 1.0 clients |
exposeModelAttributes | whether or not model attributes should be exposed as query parameters |
Set whether to interpret a given URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root.
Default is "false": A URL that starts with a slash will be interpreted as absolute, i.e. taken as-is. If "true", the context path will be prepended to the URL in such a case.
Set the encoding scheme for this view.
Default is the request's encoding scheme (which is ISO-8859-1 if not specified otherwise).
Set the exposeModelAttributes
flag which denotes whether
or not model attributes should be exposed as HTTP query parameters.
Defaults to true
.
Set whether to stay compatible with HTTP 1.0 clients.
In the default implementation, this will enforce HTTP status code 302
in any case, i.e. delegate to HttpServletResponse.sendRedirect
.
Turning this off will send HTTP status code 303, which is the correct
code for HTTP 1.1 clients, but not understood by HTTP 1.0 clients.
Many HTTP 1.1 clients treat 302 just like 303, not making any difference. However, some clients depend on 303 when redirecting after a POST request; turn this flag off in such a scenario.
Set the status code for this view.
Default is to send 302/303, depending on the value of the
http10Compatible
flag.
Append query properties to the redirect URL. Stringifies, URL-encodes and formats model attributes as query properties.
targetUrl | the StringBuilder to append the properties to |
---|---|
model | Map that contains model attributes |
encodingScheme | the encoding scheme to use |
UnsupportedEncodingException | if string encoding failed |
---|
Determines the status code to use for HTTP 1.1 compatible requests.
The default implemenetation returns the statusCode
property if set, or the value of the RESPONSE_STATUS_ATTRIBUTE
attribute.
If neither are set, it defaults to SEE_OTHER
(303).
request | the request to inspect |
---|---|
response | the servlet response |
targetUrl | the target URL |
Determine whether the given model element should be exposed as a query property.
The default implementation considers Strings and primitives as eligible, and also arrays and Collections/Iterables with corresponding elements. This can be overridden in subclasses.
key | the key of the model element |
---|---|
value | the value of the model element |
Determine whether the given model element value is eligible for exposure.
The default implementation considers primitives, Strings, Numbers, Dates, URIs, URLs and Locale objects as eligible. This can be overridden in subclasses.
value | the model element value |
---|
Determine name-value pairs for query strings, which will be stringified,
URL-encoded and formatted by appendQueryProperties(StringBuilder, Map
.
This implementation filters the model through checking
isEligibleProperty(String, Object)
for each element,
by default accepting Strings, primitives and primitive wrappers only.
model | the original model Map |
---|
Convert model to request parameters and redirect to the given URL.
model | combined output Map (never null ),
with dynamic values taking precedence over static attributes |
---|---|
request | current HTTP request |
response | current HTTP response |
IOException |
---|
Send a redirect back to the HTTP client
request | current HTTP request (allows for reacting to request method) |
---|---|
response | current HTTP response (for sending response headers) |
targetUrl | the target URL to redirect to |
http10Compatible | whether to stay compatible with HTTP 1.0 clients |
IOException | if thrown by response methods |
---|
URL-encode the given input String with the given encoding scheme.
The default implementation uses URLEncoder.encode(input, enc)
.
input | the unencoded input String |
---|---|
encodingScheme | the encoding scheme |
UnsupportedEncodingException | if thrown by the JDK URLEncoder |
---|