web.xml中设置的超时在java中不起作用 [英] Timeout set in the web.xml is not working in java

查看:521
本文介绍了web.xml中设置的超时在java中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Tomcat 7应用服务器上设置我的应用程序超时。首先我在web.xml中测试我的超时时间为一分钟

I am trying to set my application timeout on Tomcat 7 app server.First I am testing with my timeout as one minute in web.xml as

 <session-config>
       <session-timeout>1</session-timeout>
  </session-config> 

我正在使用 HttpSessionListener 以确保我的超时工作正常。我在web.xml中声明了我的sessionListener类。

and I am using HttpSessionListener to make sure my Timeout is working fine.I declared my sessionListener Class in web.xml .

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>

但是当启动我的服务器并启动我的应用程序时,我看到会话仅在登录页面上启动。 / p>

But when start my server and launch my application I see session is initiated on the Login page only .

Session ID 934073ED5E9933158995EE5EB680D3F7 created at Wed Nov 07 09:39:13 PST 2012

当我保持闲置超过一分钟或超过五分钟时,因为Tomcat不会立即在我的应用程序中触发超时并点击某些内容我的应用程序会话不是Expired.Still我能够导航另一个页面。但是当我在登录页面上停留或登出时我看到会话被破坏了。但是,一旦完成登录,当我在应用程序会话内部时,就不会发生超时。我看到

and when I stay Idle for more than a minute or some times more than five minutes cause Tomcat don't fire Timeout immediately in my application and click on something in my application Session is not Expired.Still I am able to navigate another page.But When I am stay Idle on the login page or logged-out I see the session is destroyed. But when once Login is done and when I am inside the application session timeout is not happening. I see

Session ID 934073ED5E9933158995EE5EB680D3F7 destroyed at Wed Nov 07 09:42:13 PST 2012

我做错了什么?即使我在 web.xml 中提到< session-timeout> 之后,我还需要代码 session.invalidate 代码中的某个地方?如何在JSF中销毁的会话中重定向到 login.xhtml

What am I doing wrong? And even after I mentioned <session-timeout> in web.xml do I need code session.invalidatesomewhere in Code? How Can I redirect to login.xhtml in session destroyed in JSF?

推荐答案

<你没有做错什么。当会话到期时,后台线程将每隔x分钟检查一次。这是特定于容器的。即,在您指定的时间后,不保证过期。我知道在tomcat中你可以在server.xml文件中轻松修改这个检查间隔。

Your doing nothing wrong. A background thread will check every x minutes for,when the sessions expire. This is container specific. Ie it is not guaranteed to be expired after the time you specify. I know in tomcat you can easily modify this check interval in the server.xml file.

这篇关于web.xml中设置的超时在java中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆