而不是使用ServletContextListener,使用
HttpSessionListener.在
sessionCreated()方法中,您可以以编程方式设置会话超时。
public class MyHttpSessionListener implements HttpSessionListener{
public void sessionCreated(HttpSessionEvent event){
event.getSession().setMaxInactiveInterval(15*60); //in seconds
}
public void sessionDestroyed(HttpSessionEvent event){}
}
并且不要忘记在部署描述符中定义侦听器:
...
com.example.MyHttpSessionListener
仍然,我建议为每个应用程序创建不同的web.xml文件,并定义会话超时:
...
15