服务端回话跟踪技术,将数据储存在服务端
创建Session对象来实现保存数据

对象方法

  1. setAttribute
  2. getAttribute
  3. remove
  1. 创建Session对象:
  2. Cookie[] cookies = req.getCookies();
  3. for (Cookie cookie : cookies){
  4. String name = cookie.getName();
  5. String value = cookie.getValue();
  6. }
  7. 获取Session对象:
  8. HttpSession session = req.getSession();
  9. Object username = session.getAttribute("username");
  10. System.out.println(username);