Home Spring Spring3.2 View resolvers



View resolvers
Posted on: February 7, 2013 at 12:00 AM
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.



Related Tags for View resolvers:


More Tutorials from this section

Ask Questions?    Discuss: View resolvers  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.