第一种方法:
代码中添加
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失效时间
总结:
以上方法的生效优先级为:第一种>第二种>第三种>第四种