I'm working on an old Spring project where I want to update some field in the view from my post request.

I have tried the following with no luck:

@RequestMapping(value="/dashboard/{calories}", method=RequestMethod.POST)
public void updateCals (@PathVariable Long calories, Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
            request.getSession().setAttribute("tea", tea);
    model.addAttribute("tea", tea);
}

Should I add a return or redirect at the end? Any help would be greatly appreciated

2 Answers

0
Ismail Raju On

return redirect:

@RequestMapping(value="/dashboard/{calories}", method=RequestMethod.POST)
public void updateCals (@PathVariable Long calories, Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
            request.getSession().setAttribute("tea", tea);
            model.addAttribute("tea", tea);
            return "redirect:/example";  
}
0
Prasad K On

Looks like a front-end question. Assuming this controller is going to be consumed using ajax (as you are using POST). All you have to do is change the view on callback function of your ajax call. If you want to change the view completely then Ismail Raju's answer is correct and also look into org.springframework.web.servlet.ModelAndView.