[英]GAE, GWT and HTTP Session
我正在基於Google Application Engine(GAE)和Google Web Toolkit(GWT)構建Web應用程序。
客戶端(GWT)通過以下方式與服務器交互:
服務器收到用戶點擊后,會將其存儲在數據庫中,同時還保存用戶標識符。 由於我不想使用任何形式的用戶身份驗證,因此我嘗試使用HTTP會話來區分不同的用戶。
HTTP會話是在servlet中按照以下說明創建的:
public SessionInfo getSessionInfo() {
HttpServletRequest request = this.getThreadLocalRequest();
HttpSession session = request.getSession();
if(session.isNew()) session.setMaxInactiveInterval(-1);
Integer i = (Integer) session.getAttribute("access_count");
if(i == null) {
i = new Integer(1);
} else {
i = new Integer(i.intValue()+1);
} // if
session.setAttribute("access_count", i);
SessionInfo sInfo = new SessionInfo(session.getId(), i.intValue());
return sInfo;
}
從文檔中,我了解以下說明:
session.setMaxInactiveInterval(-1);
將使會話永不過期。 但是, 每次在瀏覽器上刷新頁面時,都會創建一個新會話 。 會話已啟用。
我有兩個問題:
謝謝。
我不明白為什么每次都會創建一個新會話,所以您的代碼對我來說看起來不錯。 您可以嘗試在web.xml
設置超時,以查看是否有區別:
<session-config>
<session-timeout>-1</session-timeout>
</session-config>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.