Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

what wrong in session tracking using cookies...please

843835Jul 18 2002 — edited Jul 29 2002
in my jsp, i try to use cookies to track session. but something wrong and i can find it out. your suggestion are welcomed and will be very helpful.
in Login.jsp i wrote like;
---code ----
user = new User(name);
session = request.getSession();
String sessionId = ""+user.get_user_id()+session.getId();
Hashtable sessionInfo = new Hashtable();
sessionInfo.put("sessionId",session);
sessionInfo.put("connection",conn);
sessionInfo.put("user",user);
globalTable.put(sessionId,sessionInfo);

session.setAttribute("gHashTable",globalTable);

Cookie sessionCookie = new Cookie("JSESSIONID",sessionId);
sessionCookie.setPath("/");
response.addCookie(sessionCookie);
--- end of code login.jsp
then i use the cookie like below in other jsp
---code----
Cookie[] cookies = request.getCookies();
String sessionid = null;
Hashtable gHashTable,sessionInfo;
for(int i=0;i < cookies.length ;i++)
{ if(cookies[i].getName().equals("JSESSIONID"))
sessionid = cookies.getValue();
}
gHashTable = (Hashtable)session.getAttribute("gHashTable");
sessionInfo = (Hashtable)gHashTable.get(sessionid);

User user = (User)sessionInfo.get("user"); ....E1
Connect conn = (Connect)sessionInfo.get("connection");

when i run it , i got nullPointExcepitio in like E1
so i think the gHashTAble.get(sessionid) must return null. but i do no know why ....

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 26 2002
Added on Jul 18 2002
7 comments
107 views