session的过期时间设置

第一种方法:
代码中添加

	session.setMaxInactiveInterval(30*60);//以秒为单位,即在没有活动30分钟后,session将失效。

第二种方法:
使用shiro框架时的设置

<!--session管理器-->
    <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
        //设置7200000ms后过期。-1000为永不过期
        <property name="globalSessionTimeout" value="7200000"/>
        <property name="deleteInvalidSessions" value="true"/>
        <property name="sessionDAO" ref="sessionDAO"/>
        <property name="sessionIdCookieEnabled" value="true"/>
        <property name="sessionIdCookie" ref="sessionIdCookie"/>
        <property name="sessionValidationSchedulerEnabled" value="true"/>
        <property name="sessionValidationScheduler" ref="sessionValidationScheduler"/>
        <property name="cacheManager" ref="shiroEhcacheManager"/>
    </bean>

第三种方法:
web-inf中设置web.xml
时间单位为分钟,0或负数为永不过期

<session-config>
    <session-timeout>120</session-timeout>
</session-config>

第四种方法:
tomcat安装目录的conf文件夹下找到web.xml。tomcat默认session超时时间为30分钟,可以根据需要修改,负数或0为不限制session失效时间
在这里插入图片描述

总结:
以上方法的生效优先级为:第一种>第二种>第三种>第四种

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值