Originally posted by Pradeep Bhat:
I am not sure whether I understood your question. Are you asking how to retrieve a value set in one httpsession and put it in another ? If yes , it is not possible to do that directly. At a time you can access only one httpsession at a time. You may have to store the value in some temp location and when the request for the 2nd session comes up retrieve the value from the temp location, then store the value.
Originally posted by Adeel Ansari:
Or store the whole session object in some temp location and assign that to the other session when it is time.
Originally posted by Adeel Ansari:
Sorry if I am mistaken. But I didn't understand. If we do like
Is there any problem, except what I have already mentioned?
Originally posted by Vub bhat:
How to assign one Httpsession to another so that attribute set for the first one can be get for the second.
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Originally posted by Shailesh Chandra:
what about getServletContext().setAttribute("myAttribute",myObject);
and getServletContext().getAttribute("myAttribute");
Sorry if I am mistaken. But I didn't understand. If we do like
code:
session = request.getSession(false);
otherSession = getFromTempLocation();
session.setAttribute("otherSession",otherSession);
Is there any problem, except what I have already mentioned?
Originally posted by William Brogden:
You bet there is a problem
HttpSession objects are managed by the servlet container, you should never try to save them in your own code. As everybody has already said, you should concentrate on storing and retrieving your own object references.
Originally posted by Adeel Ansari:
I didn't really mean to do that. I know it is not considered as a best practice, I was just discussing one more option. It sounded fishy to me, though. But I dont know what kinda problem would be? Anybody please.
[ April 11, 2005: Message edited by: Adeel Ansari ]
Originally posted by Adeel Ansari:
Thanks Pardeep.
Just look at the following code.
Is this really a copy not the original one?
I have done this before. I stored all the session objects inside the application context and the app was working like champ.
Originally posted by William Brogden:
When the servlet container timed out and invalidated the session, what did you do?
Please note - when talking about Java objects it is important to distinguish between the object and the reference. You did NOT store objects in the context, you stored REFERENCES - references that were also held by the servlet container. [picky-mode]
Casually saying that you "pass an object" or "store an object" can lead to misunderstanding. [/picky-mode] As seen in some of the earlier discussion that appeared to assume you actually had a copy of the session object when what you had was a copy of the reference.
Bill
Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
For our application we are thinking of storing a userId->Session Map in the servlet context.
Originally posted by William Brogden:
When the servlet container timed out and invalidated the session, what did you do?
Please note - when talking about Java objects it is important to distinguish between the object and the reference. You did NOT store objects in the context, you stored REFERENCES - references that were also held by the servlet container.
Casually saying that you "pass an object" or "store an object" can lead to misunderstanding.
Originally posted by Yuriy Zilbergleyt:
But then how do I force-invalidate an old session when the user starts a new session while the old one is still valid?
But then how do I force-invalidate an old session when the user starts a new session while the old one is still valid?
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|