类 RedirectView
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.beans.factory.InitializingBean,cn.taketoday.context.ApplicationContextAware,SmartView,View
isEligibleProperty(String, Object) method.
A URL for this view is supposed to be an 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.
- 从以下版本开始:
- 4.0
- 作者:
- Rod Johnson, Juergen Hoeller, Colin Sampaleanu, Sam Brannen, Arjen Poutsma, Rossen Stoyanchev, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private booleanprivate Charsetprivate booleanprivate booleanprivate booleanprivate booleanprivate HttpStatusCodeprivate static final Pattern从类继承的字段 cn.taketoday.web.view.AbstractView
DEFAULT_CONTENT_TYPE从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.web.view.View
RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE -
构造器概要
构造器构造器说明Constructor for use as a bean.RedirectView(String url) Create a new RedirectView with the given URL.RedirectView(String url, boolean contextRelative) Create a new RedirectView with the given URL.RedirectView(String url, boolean contextRelative, boolean http10Compatible) Create a new RedirectView with the given URL.RedirectView(String url, boolean contextRelative, boolean http10Compatible, boolean exposeModelAttributes) Create a new RedirectView with the given URL. -
方法概要
修饰符和类型方法说明protected voidappendCurrentQueryParams(StringBuilder targetUrl, RequestContext request) Append the query string of the current request to the target redirect URL.protected voidappendQueryProperties(StringBuilder targetUrl, Map<String, Object> model, Charset encodingScheme) Append query properties to the redirect URL.protected final StringcreateTargetUrl(Map<String, Object> model, RequestContext request) Create the target URL by checking if the redirect string is a URI template first, expanding it with the given model, and then optionally appending simple type model attributes as query String parameters.private StringgetContextPath(RequestContext request) protected HttpStatusCodegetHttpStatus(RequestContext context, String targetUrl) Determines the status code to use for HTTP compatible requests.protected booleanAn ApplicationContext is not strictly required for RedirectView.protected booleanisEligibleProperty(String key, Object value) Determine whether the given model element should be exposed as a query property.protected booleanisEligibleValue(Object value) Determine whether the given model element value is eligible for exposure.booleanWhether to propagate the query params of the current URL.booleanReturns "true" indicating this view performs a redirect.queryProperties(Map<String, Object> model) Determine name-value pairs for query strings, which will be stringified, URL-encoded and formatted byappendQueryProperties(java.lang.StringBuilder, java.util.Map<java.lang.String, java.lang.Object>, java.nio.charset.Charset).protected voidrenderMergedOutputModel(Map<String, Object> model, RequestContext request) Convert model to request parameters and redirect to the given URL.protected StringBuilderreplaceUriTemplateVariables(String targetUrl, Map<String, Object> model, Map<String, String> currentUriVariables, Charset encodingScheme) Replace URI template variables in the target URL with encoded model attributes or URI variables from the current request.protected voidsendRedirect(RequestContext context, String targetUrl) Send a redirect back to the HTTP client.voidsetContextRelative(boolean contextRelative) 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.voidsetEncoding(Charset charset) Set the encoding scheme for this view.voidsetEncodingScheme(String encodingScheme) Set the encoding scheme for this view.voidsetExpandUriTemplateVariables(boolean expandUriTemplateVariables) Whether to treat the redirect URL as a URI template.voidsetExposeModelAttributes(boolean exposeModelAttributes) Set theexposeModelAttributesflag which denotes whether or not model attributes should be exposed as HTTP query parameters.voidsetHttp10Compatible(boolean http10Compatible) Set whether to stay compatible with HTTP 1.0 clients.voidsetPropagateQueryParams(boolean propagateQueryParams) When set totruethe query string of the current URL is appended and thus propagated through to the redirected URL.voidsetStatusCode(HttpStatusCode statusCode) Set the status code for this view.protected StringURL-encode the given input String with the given encoding scheme.从类继承的方法 cn.taketoday.web.view.AbstractUrlBasedView
afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toString从类继承的方法 cn.taketoday.web.view.AbstractView
addStaticAttribute, createMergedOutputModel, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestContextToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposeOutputRedirectModel, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait从接口继承的方法 cn.taketoday.web.view.View
getContentType, render
-
字段详细资料
-
URI_TEMPLATE_VARIABLE_PATTERN
-
contextRelative
private boolean contextRelative -
http10Compatible
private boolean http10Compatible -
exposeModelAttributes
private boolean exposeModelAttributes -
encoding
-
statusCode
-
expandUriTemplateVariables
private boolean expandUriTemplateVariables -
propagateQueryParams
private boolean propagateQueryParams
-
-
构造器详细资料
-
RedirectView
public RedirectView()Constructor for use as a bean. -
RedirectView
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- 另请参阅:
-
RedirectView
Create a new RedirectView with the given URL.- 参数:
url- the URL to redirect tocontextRelative- whether to interpret the given URL as relative to the current ServletContext
-
RedirectView
Create a new RedirectView with the given URL.- 参数:
url- the URL to redirect tocontextRelative- whether to interpret the given URL as relative to the current ServletContexthttp10Compatible- whether to stay compatible with HTTP 1.0 clients
-
RedirectView
public RedirectView(String url, boolean contextRelative, boolean http10Compatible, boolean exposeModelAttributes) Create a new RedirectView with the given URL.- 参数:
url- the URL to redirect tocontextRelative- whether to interpret the given URL as relative to the current ServletContexthttp10Compatible- whether to stay compatible with HTTP 1.0 clientsexposeModelAttributes- whether or not model attributes should be exposed as query parameters
-
-
方法详细资料
-
setContextRelative
public void setContextRelative(boolean contextRelative) 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.
-
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.
-
setExposeModelAttributes
public void setExposeModelAttributes(boolean exposeModelAttributes) Set theexposeModelAttributesflag which denotes whether or not model attributes should be exposed as HTTP query parameters.Defaults to
true. -
setEncodingScheme
Set the encoding scheme for this view.Default is the request's encoding scheme (which is UTF-8 if not specified otherwise).
- 抛出:
IllegalCharsetNameException- If the given charset name is illegalIllegalArgumentException- If the givencharsetNameis nullUnsupportedCharsetException- If no support for the named charset is available in this instance of the Java virtual machine
-
setEncoding
Set the encoding scheme for this view.Default is the request's encoding scheme (which is UTF-8 if not specified otherwise).
-
setStatusCode
Set the status code for this view.Default is to send 302/303, depending on the value of the
http10Compatibleflag. -
setExpandUriTemplateVariables
public void setExpandUriTemplateVariables(boolean expandUriTemplateVariables) Whether to treat the redirect URL as a URI template. Set this flag tofalseif the redirect URL contains open and close curly braces "{", "}" and you don't want them interpreted as URI variables.Defaults to
true. -
setPropagateQueryParams
public void setPropagateQueryParams(boolean propagateQueryParams) When set totruethe query string of the current URL is appended and thus propagated through to the redirected URL.Defaults to
false. -
isPropagateQueryProperties
public boolean isPropagateQueryProperties()Whether to propagate the query params of the current URL. -
isRedirectView
public boolean isRedirectView()Returns "true" indicating this view performs a redirect.- 指定者:
isRedirectView在接口中SmartView
-
isContextRequired
protected boolean isContextRequired()An ApplicationContext is not strictly required for RedirectView.- 覆盖:
isContextRequired在类中cn.taketoday.context.support.ApplicationObjectSupport
-
renderMergedOutputModel
protected void renderMergedOutputModel(Map<String, Object> model, RequestContext request) throws IOExceptionConvert model to request parameters and redirect to the given URL.- 指定者:
renderMergedOutputModel在类中AbstractView- 参数:
model- combined output Map (nevernull), with dynamic values taking precedence over static attributesrequest- current HTTP request context- 抛出:
IOException- 另请参阅:
-
createTargetUrl
Create the target URL by checking if the redirect string is a URI template first, expanding it with the given model, and then optionally appending simple type model attributes as query String parameters. -
getContextPath
-
replaceUriTemplateVariables
protected StringBuilder replaceUriTemplateVariables(String targetUrl, Map<String, Object> model, Map<String, String> currentUriVariables, Charset encodingScheme) Replace URI template variables in the target URL with encoded model attributes or URI variables from the current request. Model attributes referenced in the URL are removed from the model.- 参数:
targetUrl- the redirect URLmodel- a Map that contains model attributescurrentUriVariables- current request URI variables to useencodingScheme- the encoding scheme to use
-
getCurrentRequestUriVariables
-
appendCurrentQueryParams
Append the query string of the current request to the target redirect URL.- 参数:
targetUrl- the StringBuilder to append the properties torequest- the current request
-
appendQueryProperties
protected void appendQueryProperties(StringBuilder targetUrl, Map<String, Object> model, Charset encodingScheme) Append query properties to the redirect URL. Stringifies, URL-encodes and formats model attributes as query properties.- 参数:
targetUrl- the StringBuilder to append the properties tomodel- a Map that contains model attributesencodingScheme- the encoding scheme to use- 另请参阅:
-
queryProperties
Determine name-value pairs for query strings, which will be stringified, URL-encoded and formatted byappendQueryProperties(java.lang.StringBuilder, java.util.Map<java.lang.String, java.lang.Object>, java.nio.charset.Charset).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- 返回:
- the filtered Map of eligible query properties
- 另请参阅:
-
isEligibleProperty
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 elementvalue- the value of the model element- 返回:
- whether the element is eligible as query property
-
isEligibleValue
Determine whether the given model element value is eligible for exposure.The default implementation considers primitives, strings, numbers, dates, URIs, URLs etc as eligible, according to
BeanUtils.isSimpleValueType(java.lang.Class<?>). This can be overridden in subclasses.- 参数:
value- the model element value- 返回:
- whether the element value is eligible
- 另请参阅:
-
BeanUtils.isSimpleValueType(java.lang.Class<?>)
-
urlEncode
URL-encode the given input String with the given encoding scheme.The default implementation uses
URLEncoder.encode(input, enc).- 参数:
input- the unencoded input StringencodingScheme- the encoding scheme- 返回:
- the encoded output String
- 另请参阅:
-
sendRedirect
Send a redirect back to the HTTP client.- 参数:
context- current HTTP request (allows for reacting to request method)targetUrl- the target URL to redirect to- 抛出:
IOException- if thrown by response methods
-
getHttpStatus
Determines the status code to use for HTTP compatible requests.The default implementation returns the
statusCodeproperty if set, or the value of theView.RESPONSE_STATUS_ATTRIBUTEattribute. If neither are set, it defaults toHttpStatus.SEE_OTHER(303) ornullwhenhttp10Compatibleis true.- 参数:
context- the request to inspecttargetUrl- the target URL- 返回:
- the response status
-