是否有任何java/spring方法可以使用HttpServletRequest存储当前登录用户的会话信息?
我想知道是否可以在HttpServletRequest
对象上设置属性
我想做的是为当前登录的用户存储一些信息,以便稍后(在同一会话中)返回
我正在使用SpringMVC
到目前为止我试过这个
@RequestMapping(value = "/url1", method = RequestMethod.GET)
public void test1(final HttpServletRequest req, final ModelMap model) {
List<String> myList = (List<String>)req.getAttribute("myList");
}
@RequestMapping(value = "/url2", method = RequestMethod.GET)
public void test2(final HttpServletRequest req, final ModelMap model) {
String message = "hello world";
List<String> messages = new ArrayList<String>();
messages.add(messages);
req.setAttribute("myList", messages);
}
到目前为止,当我做req.getAttribute
时,我得到一个空值。。。有什么想法吗
# 1 楼答案
To
setAttribute
insession
应该这样使用:你可以这样得到: