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:

  1. Open our HomeController class and add one more request mapping method as follows:
    @RequestMapping("/welcome/greeting")
    public String greeting() {
      return "welcome";
    }
  2. Now, alter the return statement of the existing welcome request mapping method, and save it as follows:
    return "forward:/welcome/greeting";
  3. Now, run our application and enter http://localhost:8080/webstore/. You will be able to see a welcome message on the web page.
  4. Now, alter the return statement of the existing welcome request mapping method again and ...

Get Spring MVC Beginner’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.