Top Description Fields Constructors Methods
org.springframework.web.servlet.view

public Class InternalResourceViewResolver

extends UrlBasedViewResolver
Class Inheritance
Imports
org.springframework.lang.Nullable, org.springframework.util.ClassUtils

Convenient subclass of 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 setViewClass. 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.

Author
Juergen Hoeller
Since
17.02.2003
See Also
setViewClass, setPrefix, setSuffix, setRequestContextAttribute, InternalResourceView, JstlView

Field Summary

Modifier and TypeField and Description
private Boolean
private static final boolean
Inherited from org.springframework.web.servlet.view.UrlBasedViewResolver:
FORWARD_URL_PREFIXREDIRECT_URL_PREFIX

Constructor Summary

AccessConstructor and Description
public
InternalResourceViewResolver()

Sets the default view class to requiredViewClass: by default InternalResourceView, or JstlView if the JSTL API is present.

public
InternalResourceViewResolver(String
the prefix that gets prepended to view names when building a URL
prefix
,
String
the suffix that gets appended to view names when building a URL
suffix
)

A convenience constructor that allows for specifying prefix and suffix as constructor arguments.

Method Summary

Modifier and TypeMethod and Description
protected AbstractUrlBasedView
buildView(String
the name of the view to build
viewName
)

Overrides org.springframework.web.servlet.view.UrlBasedViewResolver.buildView.

Creates a new View instance of the specified view class and configures it.

protected AbstractUrlBasedView
protected Class<?>
requiredViewClass()

Overrides org.springframework.web.servlet.view.UrlBasedViewResolver.requiredViewClass.

Return the required type of view for this resolver.

public void
setAlwaysInclude(boolean alwaysInclude)

Specify whether to always include the view rather than forward to it.

Inherited from org.springframework.web.servlet.view.UrlBasedViewResolver:
applyLifecycleMethodscanHandlecreateViewgetAttributesMapgetCacheKeygetContentTypegetExposeContextBeansAsAttributesgetExposedContextBeanNamesgetExposePathVariablesgetOrdergetPrefixgetRedirectHostsgetRequestContextAttributegetSuffixgetViewClassgetViewNamesinitApplicationContextisRedirectContextRelativeisRedirectHttp10CompatibleloadViewsetAttributessetAttributesMapsetContentTypesetExposeContextBeansAsAttributessetExposedContextBeanNamessetExposePathVariablessetOrdersetPrefixsetRedirectContextRelativesetRedirectHostssetRedirectHttp10CompatiblesetRequestContextAttributesetSuffixsetViewClasssetViewNames

Field Detail

alwaysIncludeback to summary
private Boolean alwaysInclude
Annotations
@Nullable
jstlPresentback to summary
private static final boolean jstlPresent

Constructor Detail

InternalResourceViewResolverback to summary
public InternalResourceViewResolver()

Sets the default view class to requiredViewClass: by default InternalResourceView, or JstlView if the JSTL API is present.

InternalResourceViewResolverback to summary
public InternalResourceViewResolver(String prefix, String suffix)

A convenience constructor that allows for specifying prefix and suffix as constructor arguments.

Parameters
prefix:String

the prefix that gets prepended to view names when building a URL

suffix:String

the suffix that gets appended to view names when building a URL

Since
4.3

Method Detail

buildViewback to summary
protected AbstractUrlBasedView buildView(String viewName) throws Exception

Overrides org.springframework.web.servlet.view.UrlBasedViewResolver.buildView.

Doc from org.springframework.web.servlet.view.UrlBasedViewResolver.buildView.

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.

Parameters
viewName:String

the name of the view to build

Returns:AbstractUrlBasedView

the View instance

Annotations
@Override
Exceptions
Exception:
if the view couldn't be resolved
instantiateViewback to summary
protected AbstractUrlBasedView instantiateView()

Overrides org.springframework.web.servlet.view.UrlBasedViewResolver.instantiateView.

Doc from org.springframework.web.servlet.view.UrlBasedViewResolver.instantiateView.

Instantiate the specified view class.

The default implementation uses reflection to instantiate the class.

Returns:AbstractUrlBasedView

a new instance of the view class

Annotations
@Override
requiredViewClassback to summary
protected Class<?> requiredViewClass()

Overrides org.springframework.web.servlet.view.UrlBasedViewResolver.requiredViewClass.

Doc from org.springframework.web.servlet.view.UrlBasedViewResolver.requiredViewClass.

Return the required type of view for this resolver. This implementation returns AbstractUrlBasedView.

Annotations
@Override
setAlwaysIncludeback to summary
public void setAlwaysInclude(boolean alwaysInclude)

Specify whether to always include the view rather than forward to it.

Default is "false". Switch this flag on to enforce the use of a Servlet include, even if a forward would be possible.

See Also
InternalResourceView#setAlwaysInclude