Fork me on GitHub

java中设置session过期时间

Web容器

apache-tomcat-8.0.26\conf\web.xml中设置

<session-config>  
     <!-- 时间单位为分钟,-1为用不失效 -->  
     <session-timeout>30</session-timeout>  
</session-config>  

Web工程

在项目工程的web.xml中设置

     <session-config>
           <!-- 时间单位为分钟,-1为永不失效 -->  
           <session-timeout>15</session-timeout>
     </session-config>

Java代码

  //以秒为单位
   session.setMaxInactiveInterval(30*60);

三种方式优先级:web容器 < web项目 < java代码

 

posted @ 2019-12-20 10:10  秋夜雨巷  阅读(3874)  评论(0编辑  收藏  举报