aspose file tools*
The moose likes Servlets and the fly likes Saving Session objects in a Hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Saving Session objects in a Hashtable" Watch "Saving Session objects in a Hashtable" New topic
Author

Saving Session objects in a Hashtable

Jarrod Littlejohn
Greenhorn

Joined: Oct 03, 2001
Posts: 12
What I am trying to do.
I want a user to log into my application. I will get their session with the request object and save it in a HashTable with a name-value of - for example ("Jarrod"/jlSession), this hashtable will be saved in the servletcontext.
Simple enough you might ask, now the trick!!
I want another client to access my web app and be allowed to refresh the first clients session (I have my reasons ).
Does anyone out here know if I can get the original session out of the hashtable and somehow refresh it as if I were calling request.getSession() from first Client? Basically, I don't want that first user to timeout, I want their session to be refreshed by the second client somehow.
Thanks Java Ranchers,
Jarrod
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
You can certainly hang on to additional references to a session but there may be some problems. I don't see any method in HttpSession to refresh the timestamp - I suspect that mechanism is hidden and may vary between implementations.
There is no reason you can't implement your own equivalent to HttpSession managed by some singleton class having a timer Thread. Then you can do what you want.
Bill
Jarrod Littlejohn
Greenhorn

Joined: Oct 03, 2001
Posts: 12
Bill,
I'm a little uneasy about creating my own class that implements HttpSession. I'll be using the Servlet Container in WebLogic 6.0, it potentially may even be clustered further complicating things. I'd like to take advantage of the SessionListener interface as well.
Do you know if a call to set the timeoutvalue of the session may actually refresh the session. I suppose I could test and I'm being lazy. But this would solove my prob.
Thanks for your input.
Jarrod
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
I didn't mean you should implement HttpSession, just the functionality. All you need is a Hashtable, and a few long to represent time stamps to get similar functionality.
As for the setTimeoutValue call, since it is not specified in the API, you can't count on all implementations working the same way.
If you have WebLogic and may have clusters, I would certainly not try anything tricky.
Bill
Jarrod Littlejohn
Greenhorn

Joined: Oct 03, 2001
Posts: 12
Thanks for your help Bill. Your right there is nothing stopping me from managing the state of the user. Now I guess I have to learn how to implement something like the sessiontimeout function with sessions. Any ideas, you'd be a big help if you point me in the proper direction.
I guess I could give you a little background on what I'm doing just to make it a little more interesting for you. I'm researching a way to build a Single Sign On application for my corporation. Basically a user will pass their username/password to a servlet. The username/password will be verified and a user profile will be built and saved in the application scope. Now when a user goes from app to app within the corporation those app's will call the SSO application giving the username among other things in the request. The SSO application will check to see if he/she is logged in, refresh the user's session and send a response back to the calling app telling them the user is logged in.
Thanks again,
Jarrod
 
wood burning stoves
 
subject: Saving Session objects in a Hashtable