public static void logout(HttpServletRequest request, 
                                                          HttpServletResponse response){ 
                HttpSession session = request.getSession(); 
                session.invalidate();//这才是注销的方法                   
        } 
}

解决方案 »

  1.   

    服务器重新启动的话,会保存session到硬盘,下次启动后可以继续使用。大多数服务器默认就是这样的,比如WebLogic,只有JRun那种垃圾才不保存session(不知道最新版的JRun怎么样了)
      

  2.   

    Tomcat这样的服务器是会把session保存到硬盘上的,这些可以设置。
    JRun不是垃圾,只是用的时候问题多多。
      

  3.   

    我用Tomcat服务器,验证方式跟你的很像,不过是好用的啊,我是从Session中取一个我之前放进去的一个User对象,Tomcat重启之后,取出的user就是null了。
    不过我如果放到session里一个String类型的对象,即时重启Tomcat,我还是能从session里拿到它。我的理解是Tomcat对String有特殊对待,不知道是否正确?
    另,Tomcat我并没有进行特别的配置。
      

  4.   

    晕死,如果将保存方法写到JSP页面里,就没有问题;而且,保存是STRING类型的就会为NULL,是对象就不为NULL;
      

  5.   

    如果是服务器将SESSION保存下来了,那要如何设置,请提供具体的解决方法
      

  6.   

    Session在下列情况下被删除
    1.调用HttpSession.invalidate();
    b.距离上一次收到客户端发送的session id时间间隔超过了session的超时设置,
      即Session time out
    c.服务器进程被停止(非持久session)
      

  7.   

    tomcat在server.xml中有如下与session持久化相关的设置<!-- PersistentManager: Uncomment the section below to test Persistent 
       Sessions.
                 
       saveOnRestart: If true, all active sessions will be saved
         to the Store when Catalina is shutdown, regardless of
         other settings. All Sessions found in the Store will be 
         loaded on startup. Sessions past their expiration are
         ignored in both cases.
       maxActiveSessions: If 0 or greater, having too many active 
         sessions will result in some being swapped out. minIdleSwap
         limits this. -1 means unlimited sessions are allowed.
         0 means sessions will almost always be swapped out after
         use - this will be noticeably slow for your users.
       minIdleSwap: Sessions must be idle for at least this long
         (in seconds) before they will be swapped out due to 
       maxActiveSessions. This avoids thrashing when the site is 
         highly active. -1 or 0 means there is no minimum - sessions
         can be swapped out at any time.
       maxIdleSwap: Sessions will be swapped out if idle for this
         long (in seconds). If minIdleSwap is higher, then it will
         override this. This isn't exact: it is checked periodically.
         -1 means sessions won't be swapped out for this reason,
         although they may be swapped out for maxActiveSessions.
         If set to >= 0, guarantees that all sessions found in the
         Store will be loaded on startup.
       maxIdleBackup: Sessions will be backed up (saved to the Store,
         but left in active memory) if idle for this long (in seconds), 
         and all sessions found in the Store will be loaded on startup.
         If set to -1 sessions will not be backed up, 0 means they
         should be backed up shortly after being used.   To clear sessions from the Store, set maxActiveSessions, maxIdleSwap,
       and minIdleBackup all to -1, saveOnRestart to false, then restart 
       Catalina.
    -->
    <!--
    <Manager className="org.apache.catalina.session.PersistentManager"
      debug="0"
      saveOnRestart="true"
      maxActiveSessions="-1"
      minIdleSwap="-1"
      maxIdleSwap="-1"
      maxIdleBackup="-1">
        <Store className="org.apache.catalina.session.FileStore"/>
    </Manager>
    -->
      

  8.   

    问题解决了,只要在想应APPLICATION里的CONTEXT里加入Manager选项即可。