?? urlbasedviewresolver.java
字號:
* <p>In the default implementation, this will enforce HTTP status code 302
* in any case, i.e. delegate to <code>HttpServletResponse.sendRedirect</code>.
* 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.
* <p>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.
* <p><b>Redirect URLs can be specified via the "redirect:" prefix.</b>
* E.g.: "redirect:myAction.do"
* @see RedirectView#setHttp10Compatible
* @see #REDIRECT_URL_PREFIX
*/
public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible) {
this.redirectHttp10Compatible = redirectHttp10Compatible;
}
/**
* Return whether redirects should stay compatible with HTTP 1.0 clients.
*/
protected boolean isRedirectHttp10Compatible() {
return this.redirectHttp10Compatible;
}
/**
* Set the name of the RequestContext attribute for all views.
* @param requestContextAttribute name of the RequestContext attribute
* @see AbstractView#setRequestContextAttribute
*/
public void setRequestContextAttribute(String requestContextAttribute) {
this.requestContextAttribute = requestContextAttribute;
}
/**
* Return the name of the RequestContext attribute for all views, if any.
*/
protected String getRequestContextAttribute() {
return this.requestContextAttribute;
}
/**
* Set static attributes from a <code>java.util.Properties</code> object,
* for all views returned by this resolver.
* <p>This is the most convenient way to set static attributes. Note that
* static attributes can be overridden by dynamic attributes, if a value
* with the same name is included in the model.
* <p>Can be populated with a String "value" (parsed via PropertiesEditor)
* or a "props" element in XML bean definitions.
* @see org.springframework.beans.propertyeditors.PropertiesEditor
* @see AbstractView#setAttributes
*/
public void setAttributes(Properties props) {
setAttributesMap(props);
}
/**
* Set static attributes from a Map, for all views returned by this resolver.
* This allows to set any kind of attribute values, for example bean references.
* <p>Can be populated with a "map" or "props" element in XML bean definitions.
* @param attributes Map with name Strings as keys and attribute objects as values
* @see AbstractView#setAttributesMap
*/
public void setAttributesMap(Map attributes) {
if (attributes != null) {
this.staticAttributes.putAll(attributes);
}
}
/**
* Allow Map access to the static attributes for views returned by
* this resolver, with the option to add or override specific entries.
* <p>Useful for specifying entries directly, for example via
* "attributesMap[myKey]". This is particularly useful for
* adding or overriding entries in child view definitions.
*/
public Map getAttributesMap() {
return this.staticAttributes;
}
/**
* Set the view names (or name patterns) that can be handled by this
* {@link org.springframework.web.servlet.ViewResolver}. View names can contain
* simple wildcards such that 'my*', '*Report' and '*Repo*' will all match the
* view name 'myReport'.
* @see #canHandle
*/
public void setViewNames(String[] viewNames) {
this.viewNames = viewNames;
}
/**
* Return the view names (or name patterns) that can be handled by this
* {@link org.springframework.web.servlet.ViewResolver}.
*/
protected String[] getViewNames() {
return this.viewNames;
}
/**
* Set the order in which this {@link org.springframework.web.servlet.ViewResolver}
* is evaluated.
*/
public void setOrder(int order) {
this.order = order;
}
/**
* Return the order in which this {@link org.springframework.web.servlet.ViewResolver}
* is evaluated.
*/
public int getOrder() {
return this.order;
}
protected void initApplicationContext() {
super.initApplicationContext();
if (getViewClass() == null) {
throw new IllegalArgumentException("Property 'viewClass' is required");
}
}
/**
* This implementation returns just the view name,
* as this ViewResolver doesn't support localized resolution.
*/
protected Object getCacheKey(String viewName, Locale locale) {
return viewName;
}
/**
* Overridden to implement check for "redirect:" prefix.
* <p>Not possible in <code>loadView</code>, since overridden
* <code>loadView</code> versions in subclasses might rely on the
* superclass always creating instances of the required view class.
* @see #loadView
* @see #requiredViewClass
*/
protected View createView(String viewName, Locale locale) throws Exception {
// If this resolver is not supposed to handle the given view,
// return null to pass on to the next resolver in the chain.
if (!canHandle(viewName, locale)) {
return null;
}
// Check for special "redirect:" prefix.
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
return new RedirectView(
redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
}
// Check for special "forward:" prefix.
if (viewName.startsWith(FORWARD_URL_PREFIX)) {
String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length());
return new InternalResourceView(forwardUrl);
}
// Else fall back to superclass implementation: calling loadView.
return super.createView(viewName, locale);
}
/**
* Indicates whether or not this {@link org.springframework.web.servlet.ViewResolver} can
* handle the supplied view name. If not, {@link #createView(String, java.util.Locale)} will
* return <code>null</code>. The default implementation checks against the configured
* {@link #setViewNames view names}.
* @param viewName the name of the view to retrieve
* @param locale the Locale to retrieve the view for
* @return whether this resolver applies to the specified view
* @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
*/
protected boolean canHandle(String viewName, Locale locale) {
String[] viewNames = getViewNames();
return (viewNames == null || PatternMatchUtils.simpleMatch(viewNames, viewName));
}
/**
* Delegates to <code>buildView</code> for creating a new instance of the
* specified view class, and applies the following Spring lifecycle methods
* (as supported by the generic Spring bean factory):
* <ul>
* <li>ApplicationContextAware's <code>setApplicationContext</code>
* <li>InitializingBean's <code>afterPropertiesSet</code>
* </ul>
* @param viewName the name of the view to retrieve
* @return the View instance
* @throws Exception if the view couldn't be resolved
* @see #buildView(String)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
*/
protected View loadView(String viewName, Locale locale) throws Exception {
AbstractUrlBasedView view = buildView(viewName);
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
}
/**
* Creates a new View instance of the specified view class and configures it.
* Does <i>not</i> perform any lookup for pre-defined View instances.
* <p>Spring lifecycle methods as defined by the bean container do not have to
* be called here; those will be applied by the <code>loadView</code> method
* after this method returns.
* <p>Subclasses will typically call <code>super.buildView(viewName)</code>
* first, before setting further properties themselves. <code>loadView</code>
* will then apply Spring lifecycle methods at the end of this process.
* @param viewName the name of the view to build
* @return the View instance
* @throws Exception if the view couldn't be resolved
* @see #loadView(String, java.util.Locale)
*/
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
AbstractUrlBasedView view = (AbstractUrlBasedView) BeanUtils.instantiateClass(getViewClass());
view.setUrl(getPrefix() + viewName + getSuffix());
String contentType = getContentType();
if (contentType != null) {
view.setContentType(contentType);
}
view.setRequestContextAttribute(getRequestContextAttribute());
view.setAttributesMap(getAttributesMap());
return view;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -