<div dir="ltr" style="text-align: justify;" trbidi="on">
<div dir="ltr" style="text-align: justify;" trbidi="on">In this following example show how to write a simple web based application which makes use of redirect to transfer a<b> http request to another another page</b>. To start with it, let us have working <b>STS IDE</b> in place and follow the following steps to develop a <b>Dynamic Form based Web Application </b>using <b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/" target="_blank">Spring Web Framework</a>:</b></p>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<p>
<b><b>Step 1:</b> Create a <b><i>Dynamic Web Project</i></b> with a name <b><i>SpringMVCRedirectApp</i></b> and create a package <i><b>com</b>.<b>dineshonjava.controller</b></i> under the <b><i>src</i> </b>folder in the created project.</p>
<p><b>Step 2: </b>Add below mentioned <b>Spring 3.0 libraries</b> and other libraries into the folder <b><i>WebRoot/WEB-INF/lib</i></b>. ;<br />
</b></p>
<ul class="list">
<li>commons-logging-1.1.1.jar</li>
<li>org.springframework.asm-3.0.0.jar</li>
<li>org.springframework.beans-3.0.0.jar</li>
<li>org.springframework.context-3.0.0.jar</li>
<li>org.springframework.core-3.0.0.jar</li>
<li>org.springframework.expression-3.0.0.jar</li>
<li>org.springframework.web.servlet-3.0.0.jar</li>
<li>org.springframework.web-3.0.0.jar</li>
<li>spring-web.3.0.0.jar</li>
</ul>
<p> ;<b>Step 3: </b>Create a Java class <b><i>WebRedirectController</i> </b>under the <i><b>com</b>.<b>dineshonjava.controller</b></i> package.</p>
<p><b>Step 4:</b> Create Spring configuration files <b><i>Web.xml</i></b> and <b><i>sdnext-servlet.xml</i></b> under the <b><i>WebRoot/WEB-INF/ </i></b>folder.</p>
<p><b>Step 5:</b> Create a sub-folder with a name <i><b>views </b></i>under the <i><b>WebRoot/WEB-INF </b></i>folder. Create a view file <b><i>welcome.jsp</i></b> and <i><b>final.jsp</b></i> under this sub-folder.</p>
<p><b>Step <i>6</i>:</b> The final step is to create the content of all the source and configuration files name <i><b>sdnext-servlet.xml</b></i> under the sub-folder <i><b>WebRoot/WEB-INF/config </b></i>and export the application as explained below.<b> ;</b><b>Software versions used to run the sample code:</b></p>
<ul>
<li>Spring 3.0</li>
<li>Java 1.6</li>
<li>Tomcat 7</li>
<li>JSTL 1.2</li>
<li><b>STS</b> Java EE IDE</li>
</ul>
<div style="text-align: left;"> ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; <b>Web Application Structure:</b></div>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2012/12/redirectmvc.jpg"/></div>
<p><b>WebRedirectController.java </b></p>
<pre class="highlight" name="code">package com.dineshonjava.controller; 
 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Controller 
public class WebRedirectController { 
 @RequestMapping(value = "/welcome", method = RequestMethod.GET) 
 public String welcome() { 
 return "welcome"; 
 } 
 
 @RequestMapping(value = "/redirect", method = RequestMethod.GET) 
 public String redirect() { 
 return "redirect:finalPage"; 
 } 
 
 @RequestMapping(value = "/finalPage", method = RequestMethod.GET) 
 public String finalPage() { 
 return "final"; 
 } 
} 
</pre>
<p><b>Spring Web configuration file <i>web.xml</i></b></p>
<pre class="highlight" name="code"><;web-app id="WebApp_ID" version="3.0" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">; 
 
 <;display-name>;SpringMVCHelloWorld<;/display-name>; 
 <;welcome-file-list>; 
 <;welcome-file>;/<;/welcome-file>; 
 <;/welcome-file-list>; 
 
 <;servlet>; 
 <;servlet-name>;sdnext<;/servlet-name>; 
 <;servlet-class>; 
 org.springframework.web.servlet.DispatcherServlet 
 <;/servlet-class>; 
 <;init-param>; 
 <;param-name>;contextConfigLocation<;/param-name>;<;param-value>;/WEB-INF/config/sdnext-servlet.xml<;/param-value>;<;/init-param>; 
 <;load-on-startup>;1<;/load-on-startup>; 
 <;/servlet>; 
 <;servlet-mapping>; 
 <;servlet-name>;sdnext<;/servlet-name>; 
 <;url-pattern>;/<;/url-pattern>; 
 <;/servlet-mapping>; 
<;/web-app>; 
</pre>
<p><b>another Spring Web configuration file <i>sdnext-servlet.xml</i></b></p>
<pre class="highlight" name="code"><;beans xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" 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">; 
 
<;!-- Enable annotation driven controllers, validation etc... -->; 
<;mvc:annotation-driven>;<;/mvc:annotation-driven>; 
 
 
<;context:component-scan base-package="com.dineshonjava.controller">; 
<;/context:component-scan>; 
 
<;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver">; 
 <;property name="prefix" value="/WEB-INF/views/">;<;/property>; 
 <;property name="suffix" value=".jsp">;<;/property>; 
<;/bean>; 
 
<;/beans>; 
</pre>
<p>Following is the content of Spring view file <i><b>welcome.jsp. </b></i>This will be a landing page, this page will send a request to access redirect service method which will redirect this request to another service method and finally a <i><b>final.jsp</b></i> page will be displayed.<br />
<i><b>welcome.jsp</b></i></p>
<pre class="highlight" name="code"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
 <;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>; 
 
<;html>; 
<;head>; 
 
 <;title>;Insert title here<;/title>; 
<;/head>; 
<;body>; 
 <;h2>; 
Spring Page Redirection<;/h2>; 
Click below button to redirect the result to new page 
<;form:form action="/sdnext/redirect" method="GET">; 
<;table>;<;tbody>; 
<;tr>; <;td>;<;input type="submit" value="Redirect Page" />;<;/td>; <;/tr>; 
<;/tbody>;<;/table>; 
<;/form:form>; 
<;/body>; 
<;/html>; 
</pre>
<p>Following is the content of Spring view file <i><b>final.jsp.</b></i> This is the final redirected page.</p>
<pre class="highlight" name="code"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
 
<;html>; 
 <;head>; 
 
 <;title>;>;Spring Page Redirection<;/title>; 
 <;/head>; 
 <;body>; 
 <;h2>; 
Redirected Page<;/h2>; 
<;/body>; 
<;/html>; 
</pre>
<p>Once you are done with creating source and configuration files, export your application. Right click on your application and use <b>Export >; WAR </b>File option and save your <i><b>SpringMVCRedirectApp.war</b></i> file in Tomcat&#8217;s <b>web apps</b> folder.</p>
<p> Now start your Tomcat server and make sure you are able to access other web pages from web apps folder using a standard browser. Now try a URL<i><b> http://localhost:8080/sdnext/welcome</b></i> and you should see the following result if everything is fine with your Spring Web Application:</p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2012/12/redirectpage.jpg"/></div>
<p>Now click on<b> &#8220;Redirect Page&#8221;</b> button to submit the form and to get final redirected page. You should see the following result if everything is fine with your Spring Web Application:</p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2012/12/redirected.jpg"/></div>
<p></p>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Spring MVC Related Posts</b></span></p>
<ol style="text-align: left;"><span style="color: #274e13;"></p>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><span style="color: red;">Spring MVC Web Tutorial</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-interview-questions-and-answers/"><span style="color: red;">Spring MVC Interview Questions</span></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-mvc/"><span style="color: red;">MVC Design Pattern</span></a></b></li>
<li><b><a href="https://dineshonjava.com/what-is-dispatcherservlet-in-spring-and-its-uses/"><span style="color: red;">Spring MVC DispatcherServlet </span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC WebApplicationContext and Root Application Context</span></a></b></li>
<li><b><a href="https://dineshonjava.com/stereotype-annotations-in-spring/"><span style="color: red;">Spring MVC @Controller Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestmapping-annotation-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestMapping Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-annotation-in-spring-mvc-with-example/"><span style="color: red;">Spring MVC @RequestParam Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC ContextLoaderListener</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-vs-pathvariable-annotations-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestParam and @PathVariable annotations</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-30-mvc-hello-world-example/"><span style="color: red;">Spring MVC Hello World Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-exception-handling-example/"><span style="color: red;">Spring MVC Exception Handling Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-with-hibernate-crud-example/"><span style="color: red;">Spring MVC with Hibernate CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-tiles-plugin-with-example/"><span style="color: red;">Spring MVC Tiles Plugin with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-and-interceptor-with/"><span style="color: red;">Spring MVC Interceptor with example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/integration-spring-mvc3-and-mongodb/"><span style="color: red;">Spring MVC with MongoDB CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-internationalization/"><span style="color: red;">Spring MVC Internationalization &#038; Localization with Example</span></a></b></li>
<p></span></ol>
</div>
<div style="text-align: center;"><b><;<;</b><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/">Spring Web MVC Framework</a></b><b> |<a href="https://dineshonjava.com/spring-tutorial/">index</a>| </b><b><b><a href="https://dineshonjava.com/spring-static-pages-example/">Spring Static Pages Example</a></b></b><b>>;>;</b></div>
</div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-mvc-form-handling-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/spring-static-pages-example/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '620'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…