Let's say I've got a form for editing the properties of a Pony, and in my web application there are multiple places where you can choose to edit a Pony. For instance, in a list of Ponies there might be an "edit" link next to each Pony, and when the user is viewing a Pony, there might also be an "edit" link in that view.
When a user clicks "submit" after editing a Pony, I would like to return the user to the page that he or she was when clicking the "edit" link.
How do I write my controller to redirect the user back to where they started? Certainly I can do this by passing a parameter to the controller, but that seems a little goofy. Am I thinking about this all wrong or is that pretty much what I'll have to do?
Method SummaryAdd the supplied attribute to this Map using a generated name . Add the supplied attribute under the supplied name. Add the given flash storage using a generated name . Add the given flash attribute.
Forward: is faster, the client browser is not involved, the browser displays the original URL, the request is transfered do the forwarded URL. Redirect: is slower, the client browser is involved, the browser displays the redirected URL, it creates a new request to the redirected URL.
Here's how to do it boys (Note this is RESTful Spring 3 MVC syntax but it will work in older Spring controllers):
@RequestMapping(value = "/rate", method = RequestMethod.POST) public String rateHandler(HttpServletRequest request) { //your controller code String referer = request.getHeader("Referer"); return "redirect:"+ referer; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With