我正在尝试在Tomcat 7应用服务器上设置我的应用程序超时时间。首先,我在web.xml文件中将超时时间设置为1分钟,如下:
<session-config>
<session-timeout>1</session-timeout>
</session-config>
我正在使用HttpSessionListener来确保我的超时功能正常工作。我在web.xml文件中声明了我的sessionListener类。
public class HttpSessionChecker implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
System.out.printf("Session ID %s created at %s%n", event.getSession().getId(), new Date());
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.printf("Session ID %s destroyed at %s%n", event.getSession().getId(), new Date());
}
}
在web.xml中
<listener>
<listener-class>com.test.util.HttpSessionChecker</listener-class>
</listener>
但是当我启动服务器并启动应用程序时,我发现只有在登录页面上才会初始化会话。
Session ID 934073ED5E9933158995EE5EB680D3F7 created at Wed Nov 07 09:39:13 PST 2012
当我在应用程序中空闲时间超过一分钟或者有时甚至超过五分钟时,由于Tomcat不能立即启动超时计时器,所以当我点击应用程序中的某些东西时,Session并没有过期。我仍然能够浏览到另一个页面。但是,当我停留在登录页面或注销后,我看到Session已经被销毁。但是,一旦登录成功并且我在应用程序内部时,Session超时就不会发生。我看到...
Session ID 934073ED5E9933158995EE5EB680D3F7 destroyed at Wed Nov 07 09:42:13 PST 2012
我做错了什么?即使我在web.xml
中提到了<session-timeout>
,我需要在代码中使用session.invalidate
吗? 在JSF中,当会话被销毁时,我该如何重定向到login.xhtml
?
@SessionScoped
bean在哪里?你是先检查活动会话再处理请求,还是默默地创建一个新的会话? - kolossus