我有一个名为product的jsp页面。我已经使用ModelAndView从控制器发送一些消息到jsp页面。但它返回null。 ModelAndView的消息未设置为jsp页面。这是我的控制器代码。
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ModelAndView adduser(@ModelAttribute("productForm") Errors error, Model model) {
ModelAndView modelAndView = new ModelAndView("product");
System.out.println(modelAndView);
modelAndView.addObject("outMessage", "User Registration Success");
return new ModelAndView("redirect:/productSetup");
}
请帮助我。
答案 0 :(得分:2)
重定向时,您应该使用重定向Flash模型属性。
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ModelAndView adduser(@ModelAttribute("productForm") Errors error, RedirectAttributes redir) {
ModelAndView modelAndView = new ModelAndView("product");
System.out.println(modelAndView);
redir.addFlashAttribute("outMessage", "User Registration Success");
return new ModelAndView("redirect:/productSetup");
}