我有一些問題想代碼登錄+餅乾..當用戶登錄我創建會話getThreadLocalRequest()的getSession(假)總是空
getThreadLocalRequest().getSession(true)
,當我要檢查,如果會議的還活着總是返回null
HttpSession session = getThreadLocalRequest().getSession(false);
if (session != null) {
}
當我檢查的HttpRequest(當我檢查會話有效),這有
Cookie: JSESSIONID=a1042a8e-9ebc-45b8-a3d8-12161885be96
和cookie是好的。
我使用Eclipse +發展模式
服務器端代碼:
public String login(String rut, String pass) throws AuthenticationException {
//if UserPassMatch ...
session = this.getThreadLocalRequest().getSession(true);
//set user bean
session.setAttribute("beanSession", us);
HttpServletResponse response = getThreadLocalResponse();
Cookie usernameCookie = new Cookie("JSESSIONID", us.getSessionID());
usernameCookie.setPath("/");
usernameCookie.setMaxAge(60 * 60); //1 hora
response.addCookie(usernameCookie);
}
@Override
public String checkIfSessionStillActive(String token) {
HttpServletRequest request = getThreadLocalRequest();
//Here ALWAYS return null
HttpSession session = request.getSession(false);
if (session != null) {
//check sessionId and search User Bean
}
return token;
}
從客戶端沒有什麼特別的只是調用checkIfSessionStillActive進行檢查,如果存在會話,去扔令牌或去登錄,如果不是。當用戶登錄時仍然返回會話NULL。我使用MVP模式,我從AppController調用,並使用相同的rpcService。一旦用戶登錄我檢查會議和它的存在,但如果我打電話checkIfSessionStillActive這沒有發現任何會議。 真的,我讀了很多代碼,我發現它幾乎是一樣的東西,可以幫助我嗎?
是的,同樣的事情,cookie說會話結束時的過期時間,但仍然返回NULL。 – gfelmer