Spring MVC InternalResourceViewResolver tutorial with example


What is InternalResourceViewResolver


InternalResourceViewResolver uses prexif and suffix to locate view page

prefix + viewname (return from ModelAndView object) + suffix = url of view page


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.


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.InternalResourceViewResolver">
    
	<property name="prefix">
		<value>/WEB-INF/pages/</value>
	</property>
	
	<property name="suffix">
		<value>.jsp</value>
	</property>
	
</bean>

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

<bean name="/internalResourceViewResolver.htm" class="com.candidjava.springmvc.InternalResourceViewResolver">
</bean>
	
	<!-- ************************************************************* -->
	
</beans>

ScreenShot
            

            
Download
        InternalResourceViewResolver maven zip
        InternalResourceViewResolver war


Related Post

Comments


©candidjava.com