首页 > 其他分享 >754~755 Session原理分析,细节1

754~755 Session原理分析,细节1

时间:2023-02-11 13:22:36浏览次数:52  
标签:755 Session 754 request session Cookie 关闭 response

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的失效时间

标签:755,Session,754,request,session,Cookie,关闭,response
From: https://www.cnblogs.com/agzq/p/17111282.html

相关文章