Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the diference between "return new ModelAndView("redirect:surveys.html");" and "return new ModelAndView("surveys.html");"

The question is in the title. I got a Spring MVC Web App and I have to modify many things, I'm noob with this and before do anything I'm trying to understand how is made.

What's the difference between:

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

and

return new ModelAndView("surveys.html");

Thanks.

like image 706
user2938355 Avatar asked Feb 28 '14 09:02

user2938355


2 Answers

The first one redirects:

                  POST or GET
browser -------------------------------------> spring controller

         redirect to surveys.html (status = 302)
        <------------------------------------

                  GET
        -------------------------------------> surveys.html

                  final page
        <-------------------------------------

The second one forwards:

                    POST or GET
browser -------------------------------------> spring controller
                                                     |
                                                     |
                    final page                       V
        <------------------------------------- surveys.html
like image 64
JB Nizet Avatar answered Dec 16 '22 13:12

JB Nizet


Redirect - sends a http 302 Redirect to the client. And then the client will send a new request to the server, with the given url.

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

like image 34
Ralph Avatar answered Dec 16 '22 13:12

Ralph