为单个Web应用 配置超时时间可以在web.xml中使用<session-config>元素,如

web.xml配置Session超时时间注意的单位问题 .... 
web.xml配置Session超时时间注意的单位问题
<web-app>
web.xml配置Session超时时间注意的单位问题 
web.xml配置Session超时时间注意的单位问题
<!--filter.listener,servlet,and servlet-mapping等元素要在session-config之前-->
web.xml配置Session超时时间注意的单位问题    
<session-config>
web.xml配置Session超时时间注意的单位问题         
<session-timeout>15 </session-timeout>
web.xml配置Session超时时间注意的单位问题    
</session-config>
web.xml配置Session超时时间注意的单位问题    ... 
web.xml配置Session超时时间注意的单位问题
web.xml配置Session超时时间注意的单位问题
</web-app> 

这个时候的“15”单位是分钟!

 

如果在配置Servlet是指定初始化参数决定超时时间,例如下:

web.xml配置Session超时时间注意的单位问题....
web.xml配置Session超时时间注意的单位问题
<servlet>
web.xml配置Session超时时间注意的单位问题    
<servlet-name>Example</servlet-name>
web.xml配置Session超时时间注意的单位问题    
<servlet-class>exa.mp.le.Example2</servlet-class>
web.xml配置Session超时时间注意的单位问题    
<init-param>
web.xml配置Session超时时间注意的单位问题         
<param-name>timeout</param-name>
web.xml配置Session超时时间注意的单位问题         
<param-value>600</param-value>
web.xml配置Session超时时间注意的单位问题   
</init-param>
web.xml配置Session超时时间注意的单位问题...
web.xml配置Session超时时间注意的单位问题
</servlet>

这时候的“600”单位是秒钟!

 

另外,我们要注意HttpSession.getMaxInactiveInterval()方法返回的是与为单位的;

session.setMaxInactiveInterval(int seconds)方法参数的单位也是

相关文章: