Home Tutorial Spring Spring3 Web Spring web UrlBasedViewResolver

 
 

Share on Google+Share on Google+
Spring web UrlBasedViewResolver
Posted on: August 23, 2012 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Spring web UrlBasedViewResolver:


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: August 23, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com