• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Tracking in Wap

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic