我想配置會話超時到我的應用程序。會話超時工作不同,因爲我希望
在web.xml中我配置我分鐘,像這樣:
<session-config>
<session-timeout>1</session-timeout>
</session-config>
若要確保一切工作我創建我的聽衆,請參見:
<listener>
<listener-class>br.com.sender.util.SessionListener</listener-class>
</listener>
見我的監聽器類:
package br.com.sender.util;
import java.util.Date;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListener 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());
}
}
當我在我的應用程序登錄會話創建(在這同一時刻我存儲UserMB與sessionScope),請參閱:
Session ID 801040FAFEBC8D21C3C8E0DA56BF9B27 created at Tue Jun 10 18:44:33 BRT 2014
有些分鐘後沒有動作會被破壞:
Session ID 801040FAFEBC8D21C3C8E0DA56BF9B27 destroyed at Tue Jun 10 18:46:26 BRT 2014
當某些菜單或按鈕會話用戶點擊重新創建的,但我希望UserMB( SessionScope)被破壞,用戶必須重新登錄,但不會發生,用戶繼續使用應用程序而不重新登錄。
你是如何檢查用戶登錄?按會話!= null或通過session.getAttrribute(「someattribute」)!= null?第一個是錯誤的。 – developerwjk
我有一個UserMBLogged與SessionScope,當我需要檢查用戶是否登錄我稱之爲ManagedBean。我有一個「過濾器」來檢查用戶是否登錄。 –
您稱這個託管bean做什麼? – EJP