现在支持Google应用引擎会话吗? [英] Google app engine sessions now supported?
问题描述
http://code.google.com/appengine/docs/java /config/appconfig.html#Enabling_Sessions
表示支持:
javax.servlet.http.HttpSession
这是否意味着我们现在有servlet会话支持?如果是这样,有没有人有一个使用这个例子?我想创建自己的用户类,并支持用户登录和会话管理(我知道应用引擎已经支持谷歌用户这一点,但希望我自己的用户满足各种需求)
谢谢!
------------更新------------------- ------------------------
我把这个放在我的GreetingServiceImpl中,只是为了给它一个镜头:
public void login(String username,String password){
HttpSession session = getThreadLocalRequest()。getSession (假);
session.setAttribute(username,username);
}
然后我试着看看会话是否可以在我的登陆中发现jsp页面,在浏览器中刷新页面后:
< body>
<%
字符串username = null;
HttpSession mysession = request.getSession(false);
if(mysession.getAttribute(username)!= null){
username =(String)mysession.getAttribute(username);
}
%>
但似乎jsp页面无法解析用户登录的事实。我想如果可能的话,用户可以在登陆页面上登录。
谢谢
------------ Update 2 ------------------------------- ------------
它的工作原理,
谢谢
会话支持是GAEJ开箱即用的功能。 编写一个在会话中存储用户的登录servlet:
HttpSession session = request.getSession();
if(ProvidedUserParametersAreOK){
session.setAttribute(user,name);
然后,在调度程序servlet中对此类代码进行编码:
HttpSession session = request.getSession(false);
if(session.getAttribute(user)!= null){
User user =(User)session.getAttribute(user);
//用户登录
I thought google app engine did not support sessions (last time I checked was a few months ago). Now I was searching again for it and saw this:
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
says it supports:
javax.servlet.http.HttpSession
does this mean we have servlet session support now? If so, does anyone have an example of using this? I wanted to create my own User class and support user login and session management (I know app engine already supports this for google users, but wanted my own users for various requirements)
Thanks!
------------ Update -------------------------------------------
I put this in my GreetingServiceImpl, just to give it a shot:
public void login(String username, String password) {
HttpSession session = getThreadLocalRequest().getSession(false);
session.setAttribute("username", username);
}
then I'm trying to see if the session can be discovered in my landing jsp page, after refreshing the page in my browser:
<body>
<%
String username = null;
HttpSession mysession = request.getSession(false);
if (mysession.getAttribute("username") != null) {
username = (String)mysession.getAttribute("username");
}
%>
but it seems the jsp page cannot resolve the fact that the user is logged in. I'd like to be able to figure out that the user is logged in on the landing page when the user refreshes, if possible.
Thanks
------------ Update 2 -------------------------------------------
It works,
Thanks
Session support is a feature out of the box on GAEJ.
You could code a login servlet that store your user on session:
HttpSession session = request.getSession();
if(ProvidedUserParametersAreOK){
session.setAttribute("user", "name");
and then, code a control like this in your dispatcher servlet:
HttpSession session = request.getSession(false);
if (session.getAttribute("user") != null){
User user=(User)session.getAttribute("user");
//user logged in
这篇关于现在支持Google应用引擎会话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!