Spring-MVC controller redirect to “previous” page?

后端 未结 7 985
无人共我
无人共我 2021-01-31 18:34

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 li

7条回答
  •  后悔当初
    2021-01-31 19:21

    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;
    }
    

提交回复
热议问题