【发布时间】:2016-04-09 22:50:28
【问题描述】:
我遇到了 GAE 和会话管理问题。
我有一个端点,可以在成功登录后在会话中创建和存储用户信息。
但是,我无法在客户端检索信息。我注意到的一件事是 jsessionid 和 gae 会话 id 不同。
会话正在谷歌的数据存储中创建,但就像我说的,id 与客户端的不同 (jsessionid)。
我已经使用 servlet 而不是端点进行了测试,一切都像一个魅力一样工作......所以我为了查明根本原因所做的就是将我的代码缩减为一个非常基本的示例(见下文)。
知道根本原因是什么吗?感谢你的帮助。谢谢。
GAE 端点
@ApiMethod(name = Path.OperationUrl.TEST, path = Path.OperationUrl.TEST, httpMethod = HttpMethod.POST)
public Response test(HttpServletRequest request) throws DatabaseException {
String name = request.getParameter("name");
String pwd = request.getParameter("pwd");
//creating a session
HttpSession session = request.getSession();
session.setAttribute("name", name);
session.setAttribute("pwd", pwd);
session.setAttribute("sessionId", session.getId());
return new Response(STATUS.SUCCESS, "Session was created...." + session.getId());
}
JSP 页面
<%@ page pageEncoding="UTF-8" %>
<%@ page session="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<title>Login Page</title>
</head>
<body>
<button type="submit" onclick="callEndpoint();">Click</button>
<p>username: ${name}</p/><br>
<p>pwd: ${pwd}</p>
<script>
function callEndpoint(){
gapi.client.userEndpoint.test().execute(function(resp) {
if(resp.status === 'SUCCESS'){
alert(resp.message);
}else{
alert(resp.message);
}
});
}
</script>
<script>
function init() {
var location = window.location.origin;
gapi.client.load('userEndpoint', 'v1', null, location+'/_ah/api');
}
</script>
<script src="//apis.google.com/js/client.js?onload=init"></script>
</body>
</html>
【问题讨论】:
标签: java google-app-engine session