Share on Google+Share on Google+

View resolvers

In this section, you will learn about view resolvers in Spring.

View resolvers

In this section, you will learn about view resolvers in Spring.

In spring, for resolving view, you need to implement some view resolver. The configuration of two most commonly used view resolvers(ResourceBundleViewResolver and InternalResourceViewResolver , declared in the WebApplicationContext) are given below :

<!-- the ResourceBundleViewResolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
	<property name="basename" value="views"/>

 ResourceBundleViewResolver needs a properties file for defining view names. The property file related to the above configuration is views. properties, which is given below :



As you can see above, the property file must have mapping for 1) a class 2) a URL.

The ResourceBundleViewResolver can handle various views using only one resolver as shown below :

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
	<property name="prefix" value="/WEB-INF/jsp/"/>
	<property name="suffix" value=".jsp"/>

You must put your JSP file under 'WEB-INF' to protect it from client's direct access.



Posted on: February 7, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: View resolvers  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image