Spring MVC XmlViewResolver tutorial with example


XMLViewResolver 

        A ViewResolver implementation that uses bean definitions in a dedicated XML file for view definitions, specified by resource location. The file will typically be located in the WEB-INF directory; the default is "/WEB-INF/views.xml".
        
        This ViewResolver does not support internationalization at the level of its definition resources. Consider ResourceBundleViewResolver if you need to apply different view resources per locale.

Example
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-3.0.xsd  
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
    <!-- ************************************************************* --> 
      
<bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
	<property name="location" value="/WEB-INF/dispatcher-view.xml"/>
</bean>

<!-- ************************************************************* -->

<bean name="/xmlViewResolver.htm" class="com.candidjava.springmvc.XmlViewResolver"/>


	<!-- ************************************************************* -->
	
</beans>
dispatcher-view.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-3.0.xsd  
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
    <!-- ************************************************************* --> 
      
<bean id="page" class="org.springframework.web.servlet.view.JstlView">
	<property name="url" value="/WEB-INF/pages/page.jsp"/>
</bean>

	<!-- ************************************************************* -->
	
</beans>

Screenshot
            

            

Download
            XmlViewResolver maven download
            XMlViewReslover war

        



Related Post

Comments


©candidjava.com