org.springframework.web.servlet.view
Class RedirectView

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.view.AbstractView
              extended byorg.springframework.web.servlet.view.AbstractUrlBasedView
                  extended byorg.springframework.web.servlet.view.RedirectView
All Implemented Interfaces:
ApplicationContextAware, BeanNameAware, View

public class RedirectView
extends AbstractUrlBasedView

View that redirects to an internal or external URL, exposing all model attributes as HTTP query parameters.

A URL for this view is supposed to be a HTTP redirect URL, i.e. suitable for HttpServletResponse's sendRedirect method.

Author:
Rod Johnson, Juergen Hoeller
See Also:
HttpServletResponse.sendRedirect(java.lang.String)

Field Summary
static java.lang.String DEFAULT_ENCODING_SCHEME
           
 
Fields inherited from class org.springframework.web.servlet.view.AbstractView
DEFAULT_CONTENT_TYPE
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
RedirectView()
          Constructor for use as a bean.
RedirectView(java.lang.String url)
          Create a new RedirectView with the given URL.
RedirectView(java.lang.String url, boolean contextRelative)
          Create a new RedirectView with the given URL.
RedirectView(java.lang.String url, boolean contextRelative, boolean http10Compatible)
          Create a new RedirectView with the given URL.
 
Method Summary
protected  void appendQueryProperties(java.lang.StringBuffer targetUrl, java.util.Map model, java.lang.String encodingScheme)
          Append query properties to the redirect URL.
protected  java.util.Map queryProperties(java.util.Map model)
          Determine name-value pairs for query strings, which will be stringified, URL-encoded and formatted by appendQueryProperties.
protected  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Convert model to request parameters and redirect to the given URL.
protected  void sendRedirect(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String targetUrl, boolean http10Compatible)
          Send a redirect back to the HTTP client
 void setContextRelative(boolean contextRelative)
          Set whether to interpret the given URL as relative to the current ServletContext, i.e. as relative to the web application root.
 void setEncodingScheme(java.lang.String encodingScheme)
          Set the encoding scheme for this view.
 void setHttp10Compatible(boolean http10Compatible)
          Set whether to stay compatible with HTTP 1.0 clients.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
getUrl, initApplicationContext, setUrl
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING_SCHEME

public static final java.lang.String DEFAULT_ENCODING_SCHEME
See Also:
Constant Field Values
Constructor Detail

RedirectView

public RedirectView()
Constructor for use as a bean.


RedirectView

public RedirectView(java.lang.String url)
Create a new RedirectView with the given URL.

Parameters:
url - the URL to redirect to

RedirectView

public RedirectView(java.lang.String url,
                    boolean contextRelative)
Create a new RedirectView with the given URL.

Parameters:
url - the URL to redirect to
contextRelative - whether to interpret the given URL as relative to the current ServletContext

RedirectView

public RedirectView(java.lang.String url,
                    boolean contextRelative,
                    boolean http10Compatible)
Create a new RedirectView with the given URL.

Parameters:
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
Method Detail

setContextRelative

public void setContextRelative(boolean contextRelative)
Set whether to interpret the given URL as relative to the current ServletContext, i.e. as relative to the web application root.

Default is false: The URL will be intepreted as absolute, i.e. taken as-is. If true, the context path will be prepended to the URL.

See Also:
HttpServletRequest.getContextPath()

setHttp10Compatible

public void setHttp10Compatible(boolean http10Compatible)
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.

See Also:
HttpServletResponse.sendRedirect(java.lang.String)

setEncodingScheme

public void setEncodingScheme(java.lang.String encodingScheme)
Set the encoding scheme for this view.


renderMergedOutputModel

protected final void renderMergedOutputModel(java.util.Map model,
                                             javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response)
                                      throws java.io.IOException
Convert model to request parameters and redirect to the given URL.

Specified by:
renderMergedOutputModel in class AbstractView
Parameters:
model - combined output Map, with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
Throws:
java.io.IOException
See Also:
appendQueryProperties(java.lang.StringBuffer, java.util.Map, java.lang.String), sendRedirect(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, boolean)

appendQueryProperties

protected void appendQueryProperties(java.lang.StringBuffer targetUrl,
                                     java.util.Map model,
                                     java.lang.String encodingScheme)
                              throws java.io.UnsupportedEncodingException
Append query properties to the redirect URL. Stringifies, URL-encodes and formats model attributes as query properties.

Parameters:
targetUrl - the StringBuffer to append the properties to
model - Map that contains model attributes
encodingScheme - the encoding scheme to use
Throws:
java.io.UnsupportedEncodingException - if string encoding failed
See Also:
queryProperties(java.util.Map)

queryProperties

protected java.util.Map queryProperties(java.util.Map model)
Determine name-value pairs for query strings, which will be stringified, URL-encoded and formatted by appendQueryProperties.

This implementation returns all model elements as-is.

See Also:
appendQueryProperties(java.lang.StringBuffer, java.util.Map, java.lang.String)

sendRedirect

protected void sendRedirect(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response,
                            java.lang.String targetUrl,
                            boolean http10Compatible)
                     throws java.io.IOException
Send a redirect back to the HTTP client

Parameters:
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
Throws:
java.io.IOException - if thrown by response methods


Copyright (C) 2003-2004 The Spring Framework Project.