public class

InternalResourceViewResolver

extends UrlBasedViewResolver
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
           ↳ org.springframework.web.servlet.view.InternalResourceViewResolver

Class Overview

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(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.

Summary

[Expand]
Inherited Constants
From class org.springframework.web.servlet.view.UrlBasedViewResolver
From interface org.springframework.core.Ordered
[Expand]
Inherited Fields
From class org.springframework.context.support.ApplicationObjectSupport
Public Constructors
InternalResourceViewResolver()
Sets the default view class to requiredViewClass(): by default InternalResourceView, or JstlView if the JSTL API is present.
Public Methods
void setAlwaysInclude(boolean alwaysInclude)
Specify whether to always include the view rather than forward to it.
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.
void setExposedContextBeanNames(String[] exposedContextBeanNames)
Specify the names of beans in the context which are supposed to be exposed.
Protected Methods
AbstractUrlBasedView buildView(String viewName)
Creates a new View instance of the specified view class and configures it.
Class requiredViewClass()
This resolver requires InternalResourceView.
[Expand]
Inherited Methods
From class org.springframework.web.servlet.view.UrlBasedViewResolver
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

Public Constructors

public InternalResourceViewResolver ()

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

Public Methods

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.

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 ${...} expressions in a JSP 2.0 page, as well as in JSTL's c:out value expressions.

Default is "false".

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.

Protected Methods

protected AbstractUrlBasedView buildView (String viewName)

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 the name of the view to build
Returns
  • the View instance
Throws
Exception

protected Class requiredViewClass ()

This resolver requires InternalResourceView.