It's not a secret anymore!
The moose likes Servlets and the fly likes Session tracking in WAP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session tracking in WAP" Watch "Session tracking in WAP" New topic

Session tracking in WAP

Rama Chandra

Joined: Feb 07, 2001
Posts: 8
I have been developing some wap sites using JSP/Servlets to create dynamic wml pages. Due peculiar reasons of WAP architecture i am not able to use the usual methods like cookies and urlrewriting for session tracking.
Then the only way is using hidden fields(postfields) to pass on the session ids among the JSPs/Servlets. This session id can be retreived by calling the method
String id = request.getParameter("x");
Once you get the session id we can get a reference to the session object associated with the particular client by writing the following code in JSP.
HttpSessionContext sc = session.getSessionContext();
HttpSession hs = sc.getSession(id);
Then hs is the session object that is associated with the particular client.
But in the latest versions of the JDK the HttpSessionContext interface is deprecated so we cannot use it.
Is there an alternative method to get a reference to the
session object associated with the particular client?
Scott Stirling

Joined: Mar 05, 2001
Posts: 24
Here's a suggestion. Please let me know if this fails to meet the requirements. It's "homegrown session tracking."
Use request.getParameter("x") to test whether you need to create a new session for the client. If the parameter is null, call request.getSession() to create a new session, and use session.getId() to get the unique id. Then add the session id to the hidden field in the response, and add the id and the session object to a singleton Hashtable or HashMap that's stored in the application object (this will prevent the Hashtable of sessions from being garbage collected).
If the parameter is not null and it looks like a valid session id, then do a lookup for it in the Hashtable (or whatever collection you choose).
The other main piece you'll need is a way to timeout the sessions in the Hashtable and remove them so the Hashtable doesn't grow forever. I'll leave this exercise for you. If your app server has any kind of cron or scheduler service (e.g., JRun does) you might be able to extend that to schedule a regular cleanup of the Hastable.
Does this answer stink? Sorry. But I've read elsewhere that WAP needs improvement in this area, so I'm not sure what else to tell you. Someone else may have a more elegant solution.
Scott Stirling
Author of Java Server Pages Application Development

Scott Stirling<BR>Author of <A HREF="" TARGET=_blank rel="nofollow">Java Server Pages Application Development</A>
I agree. Here's the link:
subject: Session tracking in WAP
It's not a secret anymore!