java.lang.Object | ||||
↳ | org.springframework.context.support.ApplicationObjectSupport | |||
↳ | org.springframework.web.context.support.WebApplicationObjectSupport | |||
↳ | org.springframework.web.servlet.view.AbstractCachingViewResolver | |||
↳ | org.springframework.web.servlet.view.UrlBasedViewResolver |
Known Direct Subclasses |
Known Indirect Subclasses |
Simple implementation of the ViewResolver
interface, allowing for direct resolution of symbolic view names to URLs,
without explicit mapping definition. 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
,
VelocityView
and
FreeMarkerView
.
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.do" 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.do" 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 View for any given view name;
as a consequence, it should be configured as the last ViewResolver in the chain.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
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). | |||||||||
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). |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.core.Ordered
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.support.ApplicationObjectSupport
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Allow Map access to the static attributes for views returned by
this resolver, with the option to add or override specific entries.
| |||||||||||
Return the order in which this
ViewResolver
is evaluated. | |||||||||||
Set static attributes from a
java.util.Properties object,
for all views returned by this resolver. | |||||||||||
Set static attributes from a Map, for all views returned by this resolver.
| |||||||||||
Set the content type for all views.
| |||||||||||
Set the order in which this
ViewResolver
is evaluated. | |||||||||||
Set the prefix that gets prepended to view names when building a URL.
| |||||||||||
Set whether to interpret a given redirect URL that starts with a
slash ("/") as relative to the current ServletContext, i.e.
| |||||||||||
Set whether redirects should stay compatible with HTTP 1.0 clients.
| |||||||||||
Set the name of the RequestContext attribute for all views.
| |||||||||||
Set the suffix that gets appended to view names when building a URL.
| |||||||||||
Set the view class that should be used to create views.
| |||||||||||
Set the view names (or name patterns) that can be handled by this
ViewResolver . |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new View instance of the specified view class and configures it.
| |||||||||||
Indicates whether or not this
ViewResolver can
handle the supplied view name. | |||||||||||
Overridden to implement check for "redirect:" prefix.
| |||||||||||
This implementation returns just the view name,
as this ViewResolver doesn't support localized resolution.
| |||||||||||
Return the content type for all views, if any.
| |||||||||||
Return the prefix that gets prepended to view names when building a URL.
| |||||||||||
Return the name of the RequestContext attribute for all views, if any.
| |||||||||||
Return the suffix that gets appended to view names when building a URL.
| |||||||||||
Return the view class to be used to create views.
| |||||||||||
Return the view names (or name patterns) that can be handled by this
ViewResolver . | |||||||||||
Subclasses can override this for custom initialization behavior.
| |||||||||||
Return whether to interpret a given redirect URL that starts with a
slash ("/") as relative to the current ServletContext, i.e.
| |||||||||||
Return whether redirects should stay compatible with HTTP 1.0 clients.
| |||||||||||
Delegates to
buildView 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):
| |||||||||||
Return the required type of view for this resolver.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractCachingViewResolver
| |||||||||||
From class
org.springframework.web.context.support.WebApplicationObjectSupport
| |||||||||||
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.context.ApplicationContextAware
| |||||||||||
From interface
org.springframework.core.Ordered
| |||||||||||
From interface
org.springframework.web.context.ServletContextAware
| |||||||||||
From interface
org.springframework.web.servlet.ViewResolver
|
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.
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.
Allow Map access to the static attributes for views returned by this resolver, with the option to add or override specific entries.
Useful for specifying entries directly, for example via "attributesMap[myKey]". This is particularly useful for adding or overriding entries in child view definitions.
Return the order in which this ViewResolver
is evaluated.
Set static attributes from a java.util.Properties
object,
for all views returned by this resolver.
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.
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.
attributes | Map with name Strings as keys and attribute objects as values |
---|
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.
Set the prefix that gets prepended to view names when building a URL.
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.do"
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 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.
Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction.do"
Set the name of the RequestContext attribute for all views.
requestContextAttribute | name of the RequestContext attribute |
---|
Set the suffix that gets appended to view names when building a URL.
Set the view class that should be used to create views.
viewClass | class that is assignable to the required view class (by default, AbstractUrlBasedView) |
---|
Set the view names (or name patterns) that can be handled by this
ViewResolver
. View names can contain
simple wildcards such that 'my*', '*Report' and '*Repo*' will all match the
view name 'myReport'.
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 loadView
method
after this method returns.
Subclasses will typically call super.buildView(viewName)
first, before setting further properties themselves. loadView
will then apply Spring lifecycle methods at the end of this process.
viewName | the name of the view to build |
---|
Exception | if the view couldn't be resolved |
---|
Indicates whether or not this ViewResolver
can
handle the supplied view name. If not, createView(String, java.util.Locale)
will
return null
. The default implementation checks against the configured
view names
.
viewName | the name of the view to retrieve |
---|---|
locale | the Locale to retrieve the view for |
Overridden to implement check for "redirect:" prefix.
Not possible in loadView
, since overridden
loadView
versions in subclasses might rely on the
superclass always creating instances of the required view class.
viewName | the name of the view to retrieve |
---|---|
locale | the Locale to retrieve the view for |
null
if not found
(optional, to allow for ViewResolver chaining)Exception |
---|
This implementation returns just the view name, as this ViewResolver doesn't support localized resolution.
Return the prefix that gets prepended to view names when building a URL.
Return the name of the RequestContext attribute for all views, if any.
Return the suffix that gets appended to view names when building a URL.
Return the view names (or name patterns) that can be handled by this
ViewResolver
.
Subclasses can override this for custom initialization behavior.
The default implementation is empty. Called by
initApplicationContext(org.springframework.context.ApplicationContext)
.
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.
Return whether redirects should stay compatible with HTTP 1.0 clients.
Delegates to buildView
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):
setApplicationContext
afterPropertiesSet
viewName | the name of the view to retrieve |
---|---|
locale | the Locale to retrieve the view for |
Exception | if the view couldn't be resolved |
---|
Return the required type of view for this resolver. This implementation returns AbstractUrlBasedView.