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

user2938355 picture user2938355 · Feb 28, 2014 · Viewed 11.6k times · Source

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.

Answer

JB Nizet picture JB Nizet · Feb 28, 2014

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