Time for action – examining RedirectView
Though both redirection and forwarding are used to present a different web page than the one requested, there is a little difference between them. Let's try to understand these by examining them:
Open our
HomeController
class and add one more request mapping method as follows:@RequestMapping("/welcome/greeting") public String greeting() { return "welcome"; }
Now, alter the
return
statement of the existing welcome request mapping method, and save it as follows:return "forward:/welcome/greeting";
Now, run our application and enter
http://localhost:8080/webstore/
. You will be able to see a welcome message on the web page.Now, alter the return statement of the existing welcome request mapping method again and save it as follows:
return "redirect:/welcome/greeting";
Now, run our application and enter
http://localhost:8080/webstore/
. You will see a blank page without any welcome message.Finally, revert the return value of the
welcome
method ofHomeController...