Is there any way under spring 3.0 to access the HttpSession without including it in the method signature? What I really want to do is be able to pass in values from an HttpSession that CAN BE null.
Something like this:
@RequestMapping("/myHomePage")
public ModelAndView show(UserSecurityContext ctx) {}
instead of this:
@RequestMapping("/myHomePage")
public ModelAndView show(HttpSession session) {
UserSecurityContext ctx = (UserSecurityContext) session.getAttribute("userSecurityCtx");
}
The
@SessionAttributeannotation mentioned by @uthark is not suitable for this task – I thought it was too, but a bit of reading shows otherwise:In other words,
@SessionAttributeis for storing conversation MVC-model objects in the session (as opposed to storing them as request attributes). It’s not intended for using with arbitrary session attributes. As you discovered, it only works if the session attribute is always there.I’m not aware of any other alternative, I think you’re stuck with
HttpSession.getAttribute()