public class InternalResourceViewResolver extends UrlBasedViewResolver
UrlBasedViewResolver
that supports
InternalResourceView
(i.e. Servlets and JSPs) and subclasses
such as JstlView
.
The view class for all views generated by this resolver can be specified
via UrlBasedViewResolver.setViewClass(java.lang.Class<?>)
. See UrlBasedViewResolver
's javadoc for details.
The default is InternalResourceView
, or JstlView
if the
JSTL API is present.
BTW, it's good practice to put JSP files that just serve as views under WEB-INF, to hide them from direct access (e.g. via a manually entered URL). Only controllers will be able to access them then.
Note: When chaining ViewResolvers, an InternalResourceViewResolver always needs to be last, as it will attempt to resolve any view name, no matter whether the underlying resource actually exists.
UrlBasedViewResolver.setViewClass(java.lang.Class<?>)
,
UrlBasedViewResolver.setPrefix(java.lang.String)
,
UrlBasedViewResolver.setSuffix(java.lang.String)
,
UrlBasedViewResolver.setRequestContextAttribute(java.lang.String)
,
InternalResourceView
,
JstlView
Modifier and Type | Field and Description |
---|---|
private java.lang.Boolean |
alwaysInclude |
private static boolean |
jstlPresent |
FORWARD_URL_PREFIX, REDIRECT_URL_PREFIX
DEFAULT_CACHE_LIMIT
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
InternalResourceViewResolver()
Sets the default
view class to requiredViewClass() :
by default InternalResourceView , or JstlView if the JSTL API
is present. |
InternalResourceViewResolver(java.lang.String prefix,
java.lang.String suffix)
|
Modifier and Type | Method and Description |
---|---|
protected AbstractUrlBasedView |
buildView(java.lang.String viewName)
Creates a new View instance of the specified view class and configures it.
|
protected java.lang.Class<?> |
requiredViewClass()
This resolver requires
InternalResourceView . |
void |
setAlwaysInclude(boolean alwaysInclude)
Specify whether to always include the view rather than forward to it.
|
canHandle, createView, getAttributesMap, getCacheKey, getContentType, getExposeContextBeansAsAttributes, getExposedContextBeanNames, getExposePathVariables, getOrder, getPrefix, getRedirectHosts, getRequestContextAttribute, getSuffix, getViewClass, getViewNames, initApplicationContext, isRedirectContextRelative, isRedirectHttp10Compatible, loadView, setAttributes, setAttributesMap, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setOrder, setPrefix, setRedirectContextRelative, setRedirectHosts, setRedirectHttp10Compatible, setRequestContextAttribute, setSuffix, setViewClass, setViewNames
clearCache, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheLimit, setCacheUnresolved
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
private static final boolean jstlPresent
private java.lang.Boolean alwaysInclude
public InternalResourceViewResolver()
view class
to requiredViewClass()
:
by default InternalResourceView
, or JstlView
if the JSTL API
is present.public InternalResourceViewResolver(java.lang.String prefix, java.lang.String suffix)
prefix
- the prefix that gets prepended to view names when building a URLsuffix
- the suffix that gets appended to view names when building a URLprotected java.lang.Class<?> requiredViewClass()
InternalResourceView
.requiredViewClass
in class UrlBasedViewResolver
AbstractUrlBasedView
public void setAlwaysInclude(boolean alwaysInclude)
Default is "false". Switch this flag on to enforce the use of a Servlet include, even if a forward would be possible.
protected AbstractUrlBasedView buildView(java.lang.String viewName) throws java.lang.Exception
UrlBasedViewResolver
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.
buildView
in class UrlBasedViewResolver
viewName
- the name of the view to buildjava.lang.Exception
- if the view couldn't be resolvedUrlBasedViewResolver.loadView(String, java.util.Locale)