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?
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).]
Joined: Feb 07, 2001
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.