12:22 am - Thursday March 23, 2017

Spring MVC with Order View Resolvers Tutorial and Example

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

Spring MVC with Order View Resolvers   Tutorial and Example

dispatcher-servlet.xml

- <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
  <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
  <bean class="com.candidjava.controller.DummyController" />
- <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
- <property name="mappings">
- <props>
  <prop key="/DummyRedirectPage.htm">dummyRedirectController</prop>
  </props>
  </property>
  </bean>
- <bean id="dummyRedirectController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
  <property name="viewName" value="DummyPage" />
  </bean>
- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix">
  <value>/WEB-INF/jsp/</value>
  </property>
- <property name="suffix">
  <value>.jsp</value>
  </property>
  <property name="order" value="1" />
  </bean>
- <bean class="org.springframework.web.servlet.view.XmlViewResolver">
- <property name="location">
  <value>/WEB-INF/spring-views.xml</value>
  </property>
  <property name="order" value="0" />
  </bean>
  </beans>

DummyController.java

package com.candidjava.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class DummyController extends AbstractController{

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		return new ModelAndView("redirect:DummyRedirectPage.htm");
		//return new ModelAndView("DummyRedirect");

	}

}

DummyPage.jsp

<html>
<head>
</head>

<body>
<h2>Spring MVC RedirectView example</h2>

</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<h4 align="center">
	<u>ViewResolver-Priority</u>
</h4>
<div align="center">
	<a href="DummyRedirectPage.htm">Clik</a> here to see output for ViewResolver-Priority. <br />

</div>

web.xml

- <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <display-name>Spring Web MVC Application</display-name>
- <servlet>
  <servlet-name>dispatcher</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>
- <servlet-mapping>
  <servlet-name>dispatcher</servlet-name>
  <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
  </web-app>

&nbsp;

Output screenshots



  Download Sourcecode  +  Spring_mvc_jar

BACK


							
							
			
Filed in: Z-A Spring Codes

Comments are closed.