[英]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.