setMaxInactiveInterval(int seconds);
seconds是负数表示永不超时。
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout.

解决方案 »

  1.   

    session是要占用服务器内存的,你要设成无限长?!
      

  2.   

    以下是我的理解,也许不对!
    session的生存期是从用户打开一个页面 到关闭,
    默认好象是20分钟,如果时间较长,仅管用户没有关闭,session也失效,
    所以想设成无限长!!(也就是到用户关闭页面)
    不知对不对
      

  3.   

    我不知道你的无线长的用意何在?如果你需要一个比session作用范围更大的东东,建议参考一下appliction!无限长的session意义不大,对于客户端而言,建议使用cookie!
      

  4.   

    setMaxInactiveInterval(int seconds);
      

  5.   

    是这样的,Session是服务器传给客户端的一个令牌,然后服务器再凭借此令牌来区别客户端。与你关闭不关闭浏览器没有关系,因为你关闭浏览器后台并不知道,后台只知道你有多长时间没有和后台联系了。
      

  6.   

    setMaxInactiveInterval(int interval)Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout.
    Parameters:
    interval - An integer specifying the number of seconds看看文档吧,这个方法的参数如果是负值,就会让session永远不会失效。
      

  7.   

    如果把SESSION设置成无限长,然后自己关闭浏览器,不会有别人再用到这个信息,从用户的角度已经是安全的了,但是在服务器上, 这个SESSION一直在,终究不是什么好事
      

  8.   

    确切的说是
    session.setMaxInactiveInterval(int seconds);