Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 save it as follows:

    return "redirect:/welcome/greeting";
    
  5. Now, run our application and enter http://localhost:8080/webstore/. You will see a blank page without any welcome message.

  6. Finally, revert the return value of the welcome method of HomeController...