Spring web UrlBasedViewResolver

In this tutorial you will learn about Spring web UrlBasedViewResolver

 
 

Share on Google+Share on Google+

Spring web UrlBasedViewResolver

Ads

In this tutorial you will learn about Spring web UrlBasedViewResolver

Spring web UrlBasedViewResolver

The org.springframework.web.servlet.view.UrlBasedViewResolver the mapping between the logical view name and the URL that hands over the view class specified.

The folowing the mapping for UrlBasedViewResolver

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

The complete dispatcher-servlet.xml is given below

<?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:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="roseindia.net.controller" />

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

</beans>

Controller class is as

package roseindia.net.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AppController {
	@RequestMapping("/load-view")
	public String loadView(Model model) {
		model.addAttribute("greet","Welcome.....");
		return "welcome";
	}
}

Download Select Source Code

Advertisements

Posted on: August 23, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles