zoukankan      html  css  js  c++  java
  • session设置存活时间的三种方式

    1. 在web容器中设置(此处以tomcat为例)
      在tomcat-5.0.28confweb.xml中设置,以下是tomcat 5.0中的默认配置:
    [html] view plain copy
      <!-- ==================== Default Session Configuration ================= -->  
      <!-- You can set the default session timeout (in minutes) for all newly   -->  
      <!-- created sessions by modifying the value below.    -->  
    	<session-config>  
            <session-timeout>30</session-timeout>  
    	</session-config>  
    

    Tomcat默认session超时时间为30分钟,可以根据需要修改,负数或0为不限制session失效时间。

    1. 在工程的web.xml中设置
    [html] view plain copy
    <!-- 时间单位为分钟   -->  
    <session-config>
          <session-timeout>15</session-timeout>
    </session-config>
    
    1. 通过Java代码设置
    session.setMaxInactiveInterval(30*60);//以秒为单位

    三种方式优先级:1 < 2 < 3

    特别:如果需要根据用户或者权限去设置sessionTimeOut时间
    增加过滤器,在过滤器doFilter方法中通过request.getSession().getAttribute("userid")去得到用户然后判断用户,设置session.setMaxInactiveInterval(30); //session时间

  • 相关阅读:
    PAT1064(上)分析部分
    网络支付极其简单的体会
    L3,please send me a card
    PAT1008
    里氏转换
    数组遍历问题
    注册登录界面(简陋版)
    表单事件,onblur,onfocus,焦点
    复制所有链接,全选,反选
    剪切板
  • 原文地址:https://www.cnblogs.com/keyi/p/11401398.html
Copyright © 2011-2022 走看看