2013-05-21 52 views
1

我實現了一個SessionListener跟蹤如何在登錄時強制Tomcat刪除過期會話用戶關閉瀏覽器?

我在web.xml設置我的web服務器的開放會話:

<listener> 
    <listener-class>demo.MyHttpSessionListener</listener-class> 
</listener> 
<session-config> 
    <session-timeout>1</session-timeout> 
</session-config> 

我demo.MyHttpSessionListener.groovy:

class MyHttpSessionListener implements HttpSessionListener { 
    @Override 
    public void sessionCreated(HttpSessionEvent event) { 
    ... 
    } 

    @Override 
    public void sessionDestroyed(HttpSessionEvent event) { 
     ... 
    } 
} 

當我去我的網站sessionCreated被調用。 sessionDestroyed在我關閉瀏覽器等待會話超時時調用。

當我在我的網站上登錄並關閉我的瀏覽器時,會出現此問題。在這種情況下,會話已銷燬永遠不會在超時後調用。爲什麼當用戶登錄並關閉瀏覽器時會永遠不會被刪除? 在關閉瀏覽器並等待超時時間後,如何讓已登錄用戶的過期會話被刪除,我需要做些什麼?

+0

用戶關閉瀏覽器時無法做任何事情。當自上次會話交互後經過' 1'分鐘時,會話將自行超時。 –

+0

@SotiriosDelimanolis我知道,但過了一段時間應該處理超時。當您之前登錄時,sessionDestroyed從不會被調用,關閉瀏覽器並等待超時分鐘。 sessionDestroyed僅在沒有執行登錄的會話上調用。 – confile

+0

檢查BalusC的答案[這裏](http://stackoverflow.com/questions/1945582/how-to-call-sessiondestroyed-when-a-session-times-out)。看起來,雖然會話可能會在一分鐘後失效,但容器將不會調用'sessionDestroyed()'直到某個實現特定的時間間隔。 –

回答

0

以下是解決方案。即使你在你的web.xml中設置會話超時使用,Spring Security將覆蓋當用戶登錄該值超時設置爲:

session.maxInactiveInterval = -1 

所以,你必須爲了使再覆蓋該值會話超時工作。

相關問題