The redirect view
In a web application, URL redirection or forwarding are the techniques to move visitors to a different web page than the one they request. Most of the time, this technique is used after submitting a web form to avoid resubmission of the same form due to the event of pressing the browser's back button or refresh button. Spring MVC has a special View
object called Redirectview to handle redirection and forwarding. To use Redirectview
(org.springframework.web.servlet.view.Redirectview
) with our controller, we simply need to return the target URL string with the redirection prefix from the controller. There are two redirection prefixes available in Spring MVC, as shown in the following code snippet:
return redirect:/products/productDetail
And:
return forward:/products/productDetail