I would like to know how to read a flash attributes after redirection in Spring MVC 3.1.
I have the following code:
@Controller
@RequestMapping("/foo")
public class FooController {
@RequestMapping(value = "/bar", method = RequestMethod.GET)
public ModelAndView handleGet(...) {
// I want to see my flash attributes here!
}
@RequestMapping(value = "/bar", method = RequestMethod.POST)
public ModelAndView handlePost(RedirectAttributes redirectAttrs) {
redirectAttrs.addFlashAttributes("some", "thing");
return new ModelAndView().setViewName("redirect:/foo/bar");
}
}
What I am missing?
Use
Model, it should have flash attributes prepopulated:or, alternatively, you can use
RequestContextUtils#getInputFlashMap:P.S. You can do return
return new ModelAndView("redirect:/foo/bar");inhandlePost.EDIT:
JavaDoc says:
It doesn’t mention
ModelAndView, so maybe change handlePost to return"redirect:/foo/bar"string orRedirectView:I use
RedirectAttributesin my code withRedirectViewandmodel.asMap()method and it works OK.