为什么 Firebug 中的 Response 和 JSON 选项卡不同
我的 Servlet
public class JSONServlet extends HttpServlet {
private static Gson gson = new Gson();
public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("application/json");
res.getWriter().write(gson.toJson(returnVal));
}
}
我的登录函数
login.login=function(parm0){
$.post(login.url,
{
operation:'login',
userID: 'admin',
parmData0: JSON.stringify(parm0),
parmType0: 'com.company.share.svc.login.data.LoginData'
},
function(data){
loginHandler(data);
},
'json');
}
我如何调用我的登录函数login.login({用户ID:'admin',密码:'admin',forceOut:true});
这是 firebug 响应选项卡中的结果
{"adminUserKey":{"userID":"admin"},"resultCode":0,"sessionID":3788474425691603010,"accountInfoData":[],"userID":"admin","successful":true}
这是 firebug 中 JSON 选项卡中的结果
accountInfoData []
adminUserKey Object { userID="admin"}
resultCode 0
sessionID 3788474425691603000
successful true
userID "admin"
正如您所看到的,两个选项卡中的 sessionID 是不同的。在每个 login.login(...) 方法调用中,我都会得到一个新的会话 ID。
function(data){ //But in callback method //data.sessionID is always 3788474425691603000 //and never changes. //But sessionID in firebug Response tab changes //ever login.login(...) call and it is true one }
我做错了什么。为什么我总是得到相同的 sessionID。
My Servlet
public class JSONServlet extends HttpServlet {
private static Gson gson = new Gson();
public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("application/json");
res.getWriter().write(gson.toJson(returnVal));
}
}
My Login Function
login.login=function(parm0){
$.post(login.url,
{
operation:'login',
userID: 'admin',
parmData0: JSON.stringify(parm0),
parmType0: 'com.company.share.svc.login.data.LoginData'
},
function(data){
loginHandler(data);
},
'json');
}
How I call my login functionlogin.login({userID: 'admin', password: 'admin', forceOut: true});
This is result in firebug Response tab
{"adminUserKey":{"userID":"admin"},"resultCode":0,"sessionID":3788474425691603010,"accountInfoData":[],"userID":"admin","successful":true}
And this is result in JSON tab in firebug
accountInfoData []
adminUserKey Object { userID="admin"}
resultCode 0
sessionID 3788474425691603000
successful true
userID "admin"
As you see sessionIDs are different in two tab. In every login.login(...) method call I get a new session ID.
function(data){ //But in callback method //data.sessionID is always 3788474425691603000 //and never changes. //But sessionID in firebug Response tab changes //ever login.login(...) call and it is true one }
What am I doing wrong. Why am I getting same sessionID all time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JavaScript 在内部使用 Double(64 位浮点数)来表示数值,因此大数字的精度有限,并且会发生舍入。我使用 AJAX/JSON-stuff 遇到了这个问题,解决方案是将会话 ID 作为字符串而不是数字发送(“sessionID”:3788474425691603010 与“sessionID”:“3788474425691603010”)
JavaScript uses Doubles (64-bit floats) internally to represent numeric values, so large numbers have limited precision and rounding occurs. I've hit this problem with AJAX/JSON-stuff, the solution is to send the session-id as a string instead of a number ("sessionID":3788474425691603010 vs. "sessionID":"3788474425691603010")