How can I set session attribute using spring framework and annotation?
Something equivalent to
request.getSession().setAttribute("key", "value");
Thanks.
How can I set session attribute using spring framework and annotation?
Something equivalent to
request.getSession().setAttribute("key", "value");
Thanks.
You can pass session as an attribute of controller's method and then use it directly without request.getSession(), however it isn't a big improvement and there are no annotations :)
public String handleRequest(HttpSession session) {
session.setAttribute("key", "value");
}
EDIT:
You can also add attribute to ModelMap instance and then use @SessionAtributes annotation in these controller definitions in which you want to have that attribute inside ModelMap: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-sessionattrib