org.springframework.web.servlet.ViewResolver
interface, allowing for direct resolution of symbolic view names to URLs,
without explicit mapping definitions. This is useful if your symbolic names
match the names of your view resources in a straightforward manner
(i.e. the symbolic name is the unique part of the resource's filename),
without the need for a dedicated mapping to be defined for each view.
Supports AbstractUrlBasedView subclasses like InternalResourceView
and org..
The view class for all views generated by this resolver can be specified
via the "viewClass" property.
View names can either be resource URLs themselves, or get augmented by a specified prefix and/or suffix. Exporting an attribute that holds the RequestContext to all views is explicitly supported.
Example: prefix="/WEB-INF/jsp/", suffix=".jsp", viewname="test" → "/WEB-INF/jsp/test.jsp"
As a special feature, redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction" will trigger a redirect to the given URL, rather than resolution as standard view name. This is typically used for redirecting to a controller URL after finishing a form workflow.
Furthermore, forward URLs can be specified via the "forward:" prefix. E.g.: "forward:myAction" will trigger a forward to the given URL, rather than resolution as standard view name. This is typically used for controller URLs; it is not supposed to be used for JSP URLs - use logical view names there.
Note
This class does not support localized resolution, i.e. resolving a symbolic view name to different resources depending on the current locale.
Note
When chaining ViewResolvers, a UrlBasedViewResolver will check whether
the specified resource actually exists.
However, with InternalResourceView, it is not generally possible to
determine the existence of the target resource upfront. In such a scenario,
a UrlBasedViewResolver will always return a View for any given view name;
as a consequence, it should be configured as the last ViewResolver in the chain.
setViewClass, setPrefix, setSuffix, setRequestContextAttribute, REDIRECT_URL_PREFIX, AbstractUrlBasedView, InternalResourceView, org.springframework.web.servlet.view.freemarker.FreeMarkerView
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private Boolean | |
| private String[] | |
| private Boolean | |
| public static final String | FORWARD_URL_PREFIX
Prefix for special view names that specify a forward URL (usually to a controller after a form has been submitted and processed). |
| private int | |
| private String | |
| public static final String | REDIRECT_URL_PREFIX
Prefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed). |
| private boolean | |
| private String[] | |
| private boolean | |
| private String | |
| private final Map | staticAttributes
Map of static attributes, keyed by attribute name (String). |
| private String | |
| private Class | |
| private String[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected View | Returns: theView instance to use (either the original one
or a decorated variant)the name of the view viewName, AbstractUrlBasedView the freshly created View instance, pre-configured with
view)AbstractUrlBasedView's propertiesApply the containing |
| protected AbstractUrlBasedView | |
| protected boolean | Returns: whether this resolver applies to the specified viewthe name of the view to retrieve viewName, Locale the Locale to retrieve the view for locale)Indicates whether this |
| protected View | createView(String
the name of the view to retrieve viewName, Locale the Locale to retrieve the view for locale)Overrides org. Overridden to implement check for "redirect:" prefix. |
| public Map | getAttributesMap()
Allow |
| protected Object | getCacheKey(String viewName, Locale locale)
Overrides org. This implementation returns just the view name, as this ViewResolver doesn't support localized resolution. |
| protected String | |
| protected Boolean | |
| protected String[] | |
| protected Boolean | getExposePathVariables()
Return whether views resolved by this resolver should add path variables to the model or not. |
| public int | |
| protected String | |
| public String[] | |
| protected String | |
| protected String | |
| protected Class | |
| protected String[] | getViewNames()
Return the view names (or name patterns) that can be handled by this
|
| protected void | initApplicationContext()
Overrides org. Subclasses can override this for custom initialization behavior. |
| protected AbstractUrlBasedView | |
| protected boolean | isRedirectContextRelative()
Return whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. |
| protected boolean | |
| protected View | Returns: the View instancethe name of the view to retrieve viewName, Locale the Locale to retrieve the view for locale)Implements abstract org. Delegates to |
| protected Class | |
| public void | setAttributes(Properties props)
Set static attributes from a |
| public void | setAttributesMap(Map<String, ?>
a Map with name Strings as keys and attribute objects as values attributes)Set static attributes from a Map, for all views returned by this resolver. |
| public void | |
| public void | setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes)
Set whether to make all Spring beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed. |
| public void | setExposedContextBeanNames(String... exposedContextBeanNames)
Specify the names of beans in the context which are supposed to be exposed. |
| public void | setExposePathVariables(Boolean
Specify whether views resolved by this resolver should add path variables to the model or not. |
| public void | |
| public void | |
| public void | setRedirectContextRelative(boolean redirectContextRelative)
Set whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. |
| public void | setRedirectHosts(String...
one or more application hosts redirectHosts)Configure one or more hosts associated with the application. |
| public void | setRedirectHttp10Compatible(boolean redirectHttp10Compatible)
Set whether redirects should stay compatible with HTTP 1.0 clients. |
| public void | setRequestContextAttribute(String
name of the RequestContext attribute requestContextAttribute)Set the name of the RequestContext attribute for all views. |
| public void | |
| public void | setViewClass(Class<?>
a class that is assignable to the required view class
(by default: AbstractUrlBasedView) viewClass)Set the view class that should be used to create views. |
| public void | setViewNames(String... viewNames)
Set the view names (or name patterns) that can be handled by this
|
| contentType | back to summary |
|---|---|
| private String contentType
| |
| exposeContextBeansAsAttributes | back to summary |
|---|---|
| private Boolean exposeContextBeansAsAttributes
| |
| exposedContextBeanNames | back to summary |
|---|---|
| private String[] exposedContextBeanNames
| |
| exposePathVariables | back to summary |
|---|---|
| private Boolean exposePathVariables
| |
| FORWARD_URL_PREFIX | back to summary |
|---|---|
| public static final String FORWARD_URL_PREFIX Prefix for special view names that specify a forward URL (usually to a controller after a form has been submitted and processed). Such view names will not be resolved in the configured default way but rather be treated as special shortcut. | |
| order | back to summary |
|---|---|
| private int order | |
| prefix | back to summary |
|---|---|
| private String prefix | |
| REDIRECT_URL_PREFIX | back to summary |
|---|---|
| public static final String REDIRECT_URL_PREFIX Prefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed). Such view names will not be resolved in the configured default way but rather be treated as special shortcut. | |
| redirectContextRelative | back to summary |
|---|---|
| private boolean redirectContextRelative | |
| redirectHosts | back to summary |
|---|---|
| private String[] redirectHosts
| |
| redirectHttp10Compatible | back to summary |
|---|---|
| private boolean redirectHttp10Compatible | |
| requestContextAttribute | back to summary |
|---|---|
| private String requestContextAttribute
| |
| staticAttributes | back to summary |
|---|---|
| private final Map<String, Object> staticAttributes Map of static attributes, keyed by attribute name (String). | |
| suffix | back to summary |
|---|---|
| private String suffix | |
| viewClass | back to summary |
|---|---|
| private Class<?> viewClass
| |
| viewNames | back to summary |
|---|---|
| private String[] viewNames
| |
| UrlBasedViewResolver | back to summary |
|---|---|
| public UrlBasedViewResolver() | |
| applyLifecycleMethods | back to summary |
|---|---|
| protected View applyLifecycleMethods(String viewName, AbstractUrlBasedView view) Apply the containing
| |
| buildView | back to summary |
|---|---|
| protected AbstractUrlBasedView buildView(String viewName) throws Exception Creates a new View instance of the specified view class and configures it. Does not perform any lookup for pre-defined View instances. Spring lifecycle methods as defined by the bean container do not have to
be called here; those will be applied by the Subclasses will typically call
| |
| canHandle | back to summary |
|---|---|
| protected boolean canHandle(String viewName, Locale locale) Indicates whether this
| |
| createView | back to summary |
|---|---|
| protected View createView(String viewName, Locale locale) throws Exception Overrides org. Overridden to implement check for "redirect:" prefix. Not possible in
| |
| getAttributesMap | back to summary |
|---|---|
| public Map Allow Useful for specifying entries directly, for example via
| |
| getCacheKey | back to summary |
|---|---|
| protected Object getCacheKey(String viewName, Locale locale) Overrides org. This implementation returns just the view name, as this ViewResolver doesn't support localized resolution.
| |
| getContentType | back to summary |
|---|---|
| protected String getContentType() Return the content type for all views, if any.
| |
| getExposeContextBeansAsAttributes | back to summary |
|---|---|
protected Boolean getExposeContextBeansAsAttributes()
| |
| getExposedContextBeanNames | back to summary |
|---|---|
protected String[] getExposedContextBeanNames()
| |
| getExposePathVariables | back to summary |
|---|---|
| protected Boolean getExposePathVariables() Return whether views resolved by this resolver should add path variables to the model or not.
| |
| getOrder | back to summary |
|---|---|
| public int getOrder() Implements org. Doc from org. Get the order value of this object. Higher values are interpreted as lower priority. As a consequence,
the object with the lowest value has the highest priority (somewhat
analogous to Servlet Same order values will result in arbitrary sort positions for the affected objects.
| |
| getPrefix | back to summary |
|---|---|
| protected String getPrefix() Return the prefix that gets prepended to view names when building a URL. | |
| getRedirectHosts | back to summary |
|---|---|
| public String[] getRedirectHosts() Return the configured application hosts for redirect purposes.
| |
| getRequestContextAttribute | back to summary |
|---|---|
| protected String getRequestContextAttribute() Return the name of the RequestContext attribute for all views, if any.
| |
| getSuffix | back to summary |
|---|---|
| protected String getSuffix() Return the suffix that gets appended to view names when building a URL. | |
| getViewClass | back to summary |
|---|---|
| protected Class Return the view class to be used to create views.
| |
| getViewNames | back to summary |
|---|---|
| protected String[] getViewNames() Return the view names (or name patterns) that can be handled by this
| |
| initApplicationContext | back to summary |
|---|---|
| protected void initApplicationContext() Overrides org. Doc from org. Subclasses can override this for custom initialization behavior. The default implementation is empty. Called by
| |
| instantiateView | back to summary |
|---|---|
| protected AbstractUrlBasedView instantiateView() Instantiate the specified view class. The default implementation uses reflection to instantiate the class.
| |
| isRedirectContextRelative | back to summary |
|---|---|
| protected boolean isRedirectContextRelative() Return whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. | |
| isRedirectHttp10Compatible | back to summary |
|---|---|
| protected boolean isRedirectHttp10Compatible() Return whether redirects should stay compatible with HTTP 1.0 clients. | |
| loadView | back to summary |
|---|---|
| protected View loadView(String viewName, Locale locale) throws Exception Implements abstract org. Delegates to
| |
| requiredViewClass | back to summary |
|---|---|
| protected Class Return the required type of view for this resolver.
This implementation returns
| |
| setAttributes | back to summary |
|---|---|
| public void setAttributes(Properties props) Set static attributes from a 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. Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions. | |
| setAttributesMap | back to summary |
|---|---|
| public void setAttributesMap(Map<String, ?> attributes) 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. Can be populated with a "map" or "props" element in XML bean definitions.
| |
| setContentType | back to summary |
|---|---|
| public void setContentType(String contentType) Set the content type for all views. May be ignored by view classes if the view itself is assumed to set the content type, e.g. in case of JSPs. | |
| setExposeContextBeansAsAttributes | back to summary |
|---|---|
| public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) Set whether to make all Spring beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed. This will make all such beans accessible in plain Default is "false". | |
| setExposedContextBeanNames | back to summary |
|---|---|
| public void setExposedContextBeanNames(String... exposedContextBeanNames) Specify the names of beans in the context which are supposed to be exposed. If this is non-null, only the specified beans are eligible for exposure as attributes. | |
| setExposePathVariables | back to summary |
|---|---|
| public void setExposePathVariables(Boolean exposePathVariables) Specify whether views resolved by this resolver should add path variables to the model or not. The default setting is to let each View decide
(see
| |
| setOrder | back to summary |
|---|---|
| public void setOrder(int order) Specify the order value for this ViewResolver bean. The default value is | |
| setPrefix | back to summary |
|---|---|
| public void setPrefix(String prefix) Set the prefix that gets prepended to view names when building a URL. | |
| setRedirectContextRelative | back to summary |
|---|---|
| public void setRedirectContextRelative(boolean redirectContextRelative) Set whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. Default is "true": A redirect URL that starts with a slash will be interpreted as relative to the web application root, i.e. the context path will be prepended to the URL. Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction" | |
| setRedirectHosts | back to summary |
|---|---|
| public void setRedirectHosts(String... redirectHosts) Configure one or more hosts associated with the application. All other hosts will be considered external hosts. In effect, this property provides a way turn off encoding on redirect
via If not set (the default) all URLs are encoded through the response.
| |
| setRedirectHttp10Compatible | back to summary |
|---|---|
| public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible) Set whether redirects should 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 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. Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction" | |
| setRequestContextAttribute | back to summary |
|---|---|
| public void setRequestContextAttribute(String requestContextAttribute) Set the name of the RequestContext attribute for all views.
| |
| setSuffix | back to summary |
|---|---|
| public void setSuffix(String suffix) Set the suffix that gets appended to view names when building a URL. | |
| setViewClass | back to summary |
|---|---|
| public void setViewClass(Class<?> viewClass) Set the view class that should be used to create views.
| |
| setViewNames | back to summary |
|---|---|
| public void setViewNames(String... viewNames) Set the view names (or name patterns) that can be handled by this
| |