Home Spring Spring3.2 View resolvers
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

View resolvers

Advertisement
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"/>
</bean>

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

home.(class)=org.springframework.web.servlet.view.JstlView
home.url=/WEB-INF/jsp/home.jsp

employeeList.(class)=org.springframework.web.servlet.view.JstlView
employeeList.url=/WEB-INF/jsp/employeelist.jsp

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"/>
</bean>

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



Advertisements

Liked it!  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.

Posted on: February 7, 2013

Ask Questions?    Discuss: View resolvers  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com