佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1428|回复: 1

Session return null in Servlet

[复制链接]
发表于 16-4-2013 03:34 PM | 显示全部楼层 |阅读模式
Sorry for all because my pc does not have chinese input and is restricted by company, so I have to type in english.
I want to ask, I got an android apps and a servlet in server.
When i first login from the apps, the authentication is done in server and create a new session.
Everything is fine. When I post data again from the apps, I am not able to get the previous session in server as it returns null.
Below is the sample codes that I have written.
Apprieciate if anyone could help me on this matter.
Thank you very much.

// This is the part where after login the session is created. This is the code in servlet.
            session = createSession(request, outPool);
String sessionid = session.getId();
            response.setHeader("SESSION_ID", "JSESSIONID="+ sessionid);

//This is the part where android apps post data after login. Set the cookie into the request header to send to servlet
URL url = new URL(sbURL.toString());
conn = (HttpsURLConnection)url.openConnection();
conn.setRequestMethod("OST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if(MyApps.cookie != null)
{
                                      conn.setRequestProperty("COOKIE", MyApps.cookie);
}
                        //sending content
output = conn.getOutputStream();
output.write(szInput.getBytes());

//This is the part in servlet where it receives the data posting from android apps.

szUserIP = request.getHeader("ROXY-IP");
sysPool.set("SERVER_IP", szServerIP);
sysPool.set("REMOTE_IP", szUserIP);
String szQString = request.getQueryString();
String szUserAgent = request.getHeader("USER-AGENT");
//Here the session always get null as supposingly it should retrive the previous session created during login

session = request.getSession(false);




回复

使用道具 举报


ADVERTISEMENT

发表于 21-4-2013 03:44 PM | 显示全部楼层
虽然我不是很熟悉java的servlet, 但我能明白源码之中的意思。可能是你的android的code不能抓到最新的http request。你可以试试访问stackoverflow.com,这个网站有很多外国programmer热心解决简单的问题。或许你参考之下能不能帮助你的例子。
http://stackoverflow.com/questio ... android-and-or-java
http://stackoverflow.com/questio ... not-keeping-session
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-9-2025 03:02 AM , Processed in 0.142865 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表