Search Posts

How to Redirect in Spring MVC

Get link

Facebook

Twitter

Pinterest

Email

Other Apps

We often need to redirect our request to another controller. Its very easy to do in Spring MVC. In below code sample, I have created a controller method i.e. list which is mapper to context/users/ URL. It just displays the list of users.

There is another method i.e. save, it process the POST request and used to save data to database. I have not actually saved the data into DB because that is not our object in this post. We want to see, when save controller is called, and we have done with saving data into DB, how we can redirect our request to /users/ controller from /save/ controller method. Its very simple, below I share the code sample I have created to demonstrate the Spring MVC redirect:

The contents of Index.jsp page which is located at WEB-INF/views/users/Index.jsp location, are following. You see, in this method we have just listed the users we inserted into a collection inside our /users/ controller.