会议不工作 - GAE / J [英] Session is NOT working - GAE/J

查看:118
本文介绍了会议不工作 - GAE / J的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对GAE / J开发相当陌生,并试图使用GAE Seesion。不知何故,当我尝试检索存储在会话中的值时,它只返回null。这是我的。



我有loginservlet,我将String变量设置为session。

  HttpSession hs = req.getSession(true); 
if(hs.isNew()){
hs.setAttribute(logininfo,mylogininfo);
}

然后我尝试在JSP页面中检索这些信息 -

 <%
HttpSession hs = request.getSession(false);
String logininfo =(String)hs.getAttribute(logininfo);
%>

我总是将logininfo字符串设置为空 - 不知道为什么。



我在appengine-web.xml中启用了会话

 < ;>启用会话-;真< /会话启用> 

以上只是一个我试图运行的试用示例,我真的想将'accessToken'传递给来自servlet的JSP页面用于Facebook登录。

解决方案

我不知道你的页面被调用的顺序是什么,但最可能的罪魁祸首是使用 isNew()方法。

会话是在服务器向用户浏览器发送cookie时建立的。这发生在任何页面的第一次请求,授权或未授权。



因此, isNew() 仅在首先请求您的任何页面,而用户尚未收到任何cookie。在任何连续的请求(甚至几天之后,取决于GAE admin中的 Cookie过期:设置),它将为假。


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.

解决方案

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.

这篇关于会议不工作 - GAE / J的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆