设置Tomcat Session超时时间的三种方式

Tomcat Session过期时间

设置过期时间三种方式:

设置server.xml

<Context path="/livsorder" docBase="/home/httpd/html/livsorder"             
  isWARExpanded="true"       
 isWARValidated="false" 
 isInvokerEnabled="true"       
 isWorkDirPersistent="false"
  defaultSessionTimeOut="1800"/>

设置web.xml

<session-config>     
       
    <session-timeout>30session-timeout>    
session-config>  

利用servlet api修改

public class MyFileter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {}

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)  {
	   HttpSession session = request.getSession();
       //设置单位为秒,设置为-1永不过期。 
	   session.setMaxInactiveInterval(30*60); 
       filterChain.doFilter(servletRequest, servletResponse);
    }
    @Override
    public void destroy() {}
}

你可能感兴趣的:(JAVAEE,数据库连接池,tomcat)