what wrong in session tracking using cookies...please
843835Jul 18 2002 — edited Jul 29 2002in 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 ....