There are methods for doing this but they're deprecated for security reasons.
Now that we have session listeners, it's easy to create a context scoped map that holds references to sessions (using the session id as the key). Once this is set up, it's easy to do what you want.
As you can see, I stored the map in context scope. I created it in a contextListener to insure that it was in place before any requests could be handled.
Ben, I declared map (with static type) in SessionListener class, with 2 static method like getHttpSession() and setHttpSession().
and this two methods working fine for me !! The only problem is they are not context scoped !, then whats scope they(SessionListener class) have ? [ June 21, 2008: Message edited by: Sagar Rohankar ]
First, I assume you renamed sessionObjectMap to map or vice versa but didn't update the code posted to the ranch. If not, are you working with two different variables? If so, correct this and see if it works.
In webapps, I generally try to avoid using static variables for anything other than constants. Servlet containers rely heavily on custom class loaders so I'm never comfortable that I'm always dealing with the same class though out the application.
Binding your object (session map, in this case) to context scope is a nice, servlet spec compliant way to make that resource available to all the other objects in the application.
Is that something you're willing to try? Let us know if this work for you.
-Ben [ June 21, 2008: Message edited by: Ben Souther ]
First, I assume you renamed sessionObjectMap to map or vice versa but didn't update the code posted to the ranch.
yes Ben ,you are right ! The both objects are same, sorry for not updating the code. .
So as per your great explanation , i remove the static code from my webapps, and put that code in ContextListener class. And thats too working fine , with greater reliability in future !