繁体   English   中英

是否有任何Java / spring方式使用HttpServletRequest为当前登录用户存储会话信息?

[英]is there any java/spring way to store session information for the current logged user using the HttpServletRequest?

我想知道是否可以在HttpServletRequest对象上设置属性。

我要做的是为当前登录的用户存储一些信息,以后我可以在同一会话中找回这些信息。

我正在使用Spring MVC。

到目前为止,我尝试了

@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我得到一个空值。

要在session中使用setAttribute应该像这样:

 request.getSession().setAttribute("myList", messages);

你可以这样得到:

 request.getSession().getAttribute("myList");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM