Spring MVC Page Redirection Example - Spring MVC Framework

What is Spring MVC Page Redirection Example?

The below example explains the readers on how to write a web based application making use of redirect to transfer a http request to another page. Firstly, a working Eclipse IDE should be in place and follow the steps below to create a Dynamic Form based Web Application.

Step Description
1 Create aDynamic Web Projectwith a nameHelloWeband create a packagecom.wisdomjobsunder thesrcfolder in the created project.
2 Drag and drop below mentioned Spring and other libraries into the folderWebContent/WEB-INF/lib.
3 Create a Java classWebControllerunder thecom.wisdomjobspackage.
4 Create Spring configuration filesWeb.xmlandHelloWeb-servlet.xmlunder theWebContent/WEB-INFfolder.
5 Create a sub-folder with a namejspunder theWebContent/WEB-INFfolder. Create view filesindex.jspandfinal.jspunder this sub-folder.
6 The final step is to create the content of all the source and configuration files and export the application as explained below.


Following is the content of Spring Web configuration file web.xml
Following is the content of another Spring Web configuration file HelloWeb-servlet.xml

Below is the content of view file i.e., index.jsp. This page will send request to make use of redirect service which redirects the request to other service method and finally a final.jsp page will be displayed.


Following is the content of Spring view file final.jsp. This is the final redirected page.

Finally, following is the list of Spring and other libraries to be included in your web application. You simply drag these files and drop them in WebContent/WEB-INF/lib folder.

  • commons-logging-x.y.z.jar
  • org.springframework.asm-x.y.z.jar
  • org.springframework.beans-x.y.z.jar
  • org.springframework.context-x.y.z.jar
  • org.springframework.core-x.y.z.jar
  • org.springframework.expression-x.y.z.jar
  • org.springframework.web.servlet-x.y.z.jar
  • org.springframework.web-x.y.z.jar
  • spring-web.jar

Once the source and configuration files are created export the application. Do right click on the application and Export > WAR File option and save SpringWeb.war file in Tomcat’s webapps folder.

Start the Tomcat Server and using a standard browser check if you are having access to other web pages from webapps folder. Try the URL http://localhost:8080/SpringWeb/student and you must see the below result if everything is fine with Spring Web Application:

Spring Redirect Form

Submit the form by clicking “Redirect Page“ buttononce the required information is filled to get redirected page. You must see the below result if everything is fine with Spring Web Application:

Spring Redirect Form Result

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Spring MVC Framework Topics