LoginController,怎么在判断用户名密码都对之后,把用户名保存,然后在另外一个Controller中取出。。。
保存到application域中,application在整个项目中都可用~~
网上看了好多资料,经过楼上提示得以解决:
存数据:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext application = webApplicationContext.getServletContext();
application.setAttribute("name",name);
取数据:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext application = webApplicationContext.getServletContext();
application.getAttribute("name");
希望有所帮助
用session.
request.getSession().setAttribute("userName", userName);
然后在另一个controller中取出这个session:
String userName = request.getSession().getAttribute("userName");