3. 原理
Session的实现是依赖于Cookie的。
4.细节:
1.当客户端关闭后,服务器不关闭,两次获取session是否为同一个
默认情况下。不是
@WebServlet("/sessionDemo3") public class SessionDemo3 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1.获取session HttpSession session = request.getSession(); System.out.println(session); //期望客户端关闭后,session也能相同 Cookie c = new Cookie("JSESSIONID",session.getId()); c.setMaxAge(60*60); response.addCookie(c); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } }
2.客户端不关闭,服务器关闭后,两次获取的Session是同一个吗?
3.Session的失效时间