需求:
后端将信息存入session中,想要从前端中取出。
controller层
@GetMapping("/testSession")
public String testSession(HttpServletRequest request){
request.getSession().setAttribute("username","zhaoruihang");
return "testSession1";
}
view层
hello
问题:
无法从session取得username
解决方法:
直接在testSession方法中加上HttpSession参数即可,这样view层就能取到session值。
其中原理还不知道,等到知道了以后再来补充。
@GetMapping("/testSession")
public String testSession(HttpServletRequest request,HttpSession session){
session.setAttribute("username","zhaoruihang");
return "testSession1";
}