session

1):session创建:当第一次访问的时候,session="false" ,服务器不会为jsp创建一个HttpSession对象。

       当不是第一次访问的时候,session="false",其它页面已经有了HttpSession对象。则不会创建。会把那个对象给返回到当前JSP页面

        对于Servlet 。只有调用request.getSession() 或者request.getSession(true) ,才会创建一个HttpSession对象。

2):在Servlet中如何获取HttpSession对象?

  request.getSession(boolean create):

    create为FALSE,若没有和当前JSP页面相关联的HttpSession对象。则返回null。有 就返回TRUE;

    create为TRUE,一定有一个HttpSession对象,如果有和JSP页面关联的,直接返回,没有就创建一个。

  request.getSession():等同于request.getSession(true);

3):销毁HttpSession对象

  调用invalidate()

  服务器卸载当前应用;

  超出Session的时间范围:session.setMaxInactiveInterval(30);   30秒的时间内是有效的,默认是1800秒

原文地址:https://www.cnblogs.com/bulrush/p/6673543.html