What is the difference between "returning a new ModelAndView (" redirect: survey.html "); and" returning a new ModelAndView ("survey.html");

The question is in the title. I got the Spring MVC web application, and I have a lot to change, but I have done everything with it before that I am trying to understand how this is done.

What's the difference between:

return new ModelAndView("redirect:surveys.hmtl"); 

and

 return new ModelAndView("surveys.html"); 

Thanks.

+6
source share
3 answers

The first redirects:

  POST or GET browser -------------------------------------> spring controller redirect to surveys.html (status = 302) <------------------------------------ GET -------------------------------------> surveys.html final page <------------------------------------- 

Second ahead:

  POST or GET browser -------------------------------------> spring controller | | final page V <------------------------------------- surveys.html 
+12
source

Redirection - sends http 302 Redirect to the client. And then the client will send a new request to the server with the specified URL.

while return new ModelAndView("surveys.html"); instruct spring to return this view to the client

+1
source

From a programmer’s point of view, this means that

return new ModelAndView("redirect:surveys.hmtl"); when you use redirection, you redirect your controller to another one that is applicable to the redirected URL. Simply put, you can have a controller that processes this path. And this controller will be launched. And it can redirect to another page. And then in the HTTP response you can see the redirected status 3xx is not 200, as in the usual case.

 return new ModelAndView("surveys.html"); 

If you are not using redirection, you only call the View part and display your html. In the response state, HTTP 200 / OK is.

0
source

All Articles