aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Tracking in Wap" Watch "Session Tracking in Wap" New topic
Author

Session Tracking in Wap

Rama Chandra
Greenhorn

Joined: Feb 07, 2001
Posts: 8
Sir,
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?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252

And bind them to the servlet context:

Next, the sessions themselves. In its simplest form, a session is nothing but a mapping from Strings to Objects. In addition to that, in order to eventually expire sessions you need to track when they were last accessed.

To retrieve a session, you would get the manager out of the servlet context:

The final ingredient is a daemon thread that every now and then goes through the sessions object in the WapSessionManager and cleans out all expired sessions. A quick and dirty way would be to add a WapSessionManager constructor spawning this thread:

Note that the above was written on the fly, it probably doesn't even compile. There may be a few details that aren't quite right (watch out thread safety).
More importantly, I glossed over a few details, such as the fact that it isn't possible to retrieve a session from the WapSessionManager while the expiry thread is iterating through its collection (solution: let it make a copy of the values Collection and do the iteration outside the synchronized block. When you think you have a session that's expired, synchronize again, check again, and remove. Also, you may want a way to clean the WapSessionManager including interrupting the expiry thread.
HTH
- Peter

[This message has been edited by Peter den Haan (edited February 08, 2001).]
Rama Chandra
Greenhorn

Joined: Feb 07, 2001
Posts: 8
Dear Peter,
Thank you for your elaborate and innovative solution for
session tracking in wap.
But, here we are taking control of the management of the sessions instead of using the functionality of the server. I feel
it is very difficult to duplicate all the functionality of the server especially like session swapping, memmory management etc.
Is there any way to get the reference to the session object
associated with a particular client so that we can take advantage of functionality of the server.
Thanking you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Tracking in Wap
 
Similar Threads
Session tracking in WAP
Session Tracking in Wap
Will the container take care with session tracking
Invalidating all sessions
Session Tracking