Reputation: 251
I am fairly new to GAE/J development and trying to use GAE Seesion. Somehow when i try to retrieve value stored in session, its coming back null only. Here is what i have.
I have loginservlet where i am setting String variable to session.
HttpSession hs=req.getSession(true);
if(hs.isNew()){
hs.setAttribute("logininfo", "mylogininfo");
}
then I try to retrieve this information inside JSP page as below -
<%
HttpSession hs = request.getSession(false);
String logininfo = (String) hs.getAttribute("logininfo");
%>
I am always getting "logininfo" string as null - not sure why.
I have session enabled inside appengine-web.xml
<sessions-enabled>true</sessions-enabled>
Above is just a trial example I am trying to run, i really want to pass 'accessToken' to JSP page from servlet for facebook login.
Upvotes: 1
Views: 267
Reputation: 80350
I don't know in what order your pages are called, but the most probable culprit is the use of isNew()
method.
Sessions are established when server sends a cookie to users browser. This happens on first request of any page, authorized or non-authorized.
So, isNew()
is true only on the first request to any of your pages, while user has not yet received any cookie. On any consecutive request (even days later, depends on Cookie Expiration:
setting in GAE admin) it will be false.
Upvotes: 1