一、代码设置方法
request.getSession().setMaxInactiveInterval(-1);//设置session永不过期
request.getSession().setMaxInactiveInterval(30*60);//单位秒 这里的优先级高于web.xml设置的超时
二、设置web.xml
<session-config>
<session-timeout>1440</session-timeout><!--单位是分钟1440是24小时-->
</session-config>
第一种方法优先级高于第二种,也就是说设置了第一种,第二种就会失效