服务端回话跟踪技术,将数据储存在服务端
创建Session对象来实现保存数据
对象方法
- setAttribute
- getAttribute
- remove
创建Session对象:Cookie[] cookies = req.getCookies();for (Cookie cookie : cookies){String name = cookie.getName();String value = cookie.getValue();}获取Session对象:HttpSession session = req.getSession();Object username = session.getAttribute("username");System.out.println(username);
