HDIV API 2.0.4

org.hdiv.web.servlet.view
Class RedirectViewHDIV

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.view.AbstractView
              extended by org.springframework.web.servlet.view.AbstractUrlBasedView
                  extended by org.springframework.web.servlet.view.RedirectView
                      extended by org.hdiv.web.servlet.view.RedirectViewHDIV
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.View

public class RedirectViewHDIV
extends org.springframework.web.servlet.view.RedirectView

View that redirects to an absolute, context relative, or current request relative 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, 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 apps 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 that in a Servlet 2.2 environment, i.e. a servlet container which is only compliant to the limits of this spec, this class will probably fail when feeding in URLs which are not fully absolute, or relative to the current request (no leading "/"), as these are the only two types of URL that sendRedirect supports in a Servlet 2.2 environment.

Since:
HDIV 2.0.1
Author:
Gorka Vicente
See Also:
RedirectView.setHttp10Compatible(boolean), HttpServletResponse.sendRedirect(java.lang.String)

Field Summary
 
Fields inherited from class org.springframework.web.servlet.view.RedirectView
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
RedirectViewHDIV()
          Constructor for use as a bean.
RedirectViewHDIV(java.lang.String url)
          Create a new RedirectView with the given URL.
RedirectViewHDIV(java.lang.String url, boolean contextRelative)
          Create a new RedirectView with the given URL.
RedirectViewHDIV(java.lang.String url, boolean contextRelative, boolean http10Compatible)
          Create a new RedirectView with the given URL.
 
Method Summary
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 and adds HDIV state as a parameter if targetUrl references our application.
 
Methods inherited from class org.springframework.web.servlet.view.RedirectView
appendQueryProperties, queryProperties, renderMergedOutputModel, setContextRelative, setEncodingScheme, setHttp10Compatible, urlEncode
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
afterPropertiesSet, getUrl, setUrl, toString
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, exposeModelAsRequestAttributes, 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, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RedirectViewHDIV

public RedirectViewHDIV()
Constructor for use as a bean.


RedirectViewHDIV

public RedirectViewHDIV(java.lang.String url)
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.

Parameters:
url - the URL to redirect to
See Also:
#RedirectView(String, boolean)

RedirectViewHDIV

public RedirectViewHDIV(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

RedirectViewHDIV

public RedirectViewHDIV(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

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 and adds HDIV state as a parameter if targetUrl references our application.

Overrides:
sendRedirect in class org.springframework.web.servlet.view.RedirectView
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

HDIV 2.0.4

Copyright © 2008 hdiv.org. All Rights Reserved.