为单个Web应用 配置超时时间可以在web.xml中使用<session-config>元素,如
<web-app>
2个区别搞懂web.xml配置Session超时时间_session
2个区别搞懂web.xml配置Session超时时间_session<!–filter.listener,servlet,and servlet- mapping等元素要在session-config之前–>
2个区别搞懂web.xml配置Session超时时间_session <session-config>
2个区别搞懂web.xml配置Session超时时间_session <session-timeout>15 </session-timeout>
2个区别搞懂web.xml配置Session超时时间_session </session-config>
2个区别搞懂web.xml配置Session超时时间_session …
2个区别搞懂web.xml配置Session超时时间_session
2个区别搞懂web.xml配置Session超时时间_session</web-app>
这个时候的“15”单位是分钟!
 
如果在配置Servlet是指定初始化参数决定超时时间,例如下:
<servlet>
2个区别搞懂web.xml配置Session超时时间_session <servlet-name>Example</servlet-name>
2个区别搞懂web.xml配置Session超时时间_session <servlet-class>exa.mp.le.Example2</servlet-class>
2个区别搞懂web.xml配置Session超时时间_session <init-param>
2个区别搞懂web.xml配置Session超时时间_session <param-name>timeout</param-name>
2个区别搞懂web.xml配置Session超时时间_session <param-value>600</param-value>
2个区别搞懂web.xml配置Session超时时间_session </init-param>
2个区别搞懂web.xml配置Session超时时间_session
2个区别搞懂web.xml配置Session超时时间_session</servlet>
这时候的“600”单位是秒钟!
另外,我们要注意HttpSession.getMaxInactiveInterval()方法返回的是与为单位的;
session.setMaxInactiveInterval(int seconds)方法参数的单位也是