how to access the "real" session?

16 views
Skip to first unread message

Dennis Haupt

unread,
Aug 12, 2011, 2:37:43 PM8/12/11
to google-we...@googlegroups.com
i tried to save an attribute via an async servlet call to get it later from another page. i did it like this:

class x extends remoteserviceservlet
...
final Object attribute = getThreadLocalRequest().getSession().getAttribute(variableName);
....

but this doesn't work. the result seems to depend on a mysterious something. i suspect it being the thread itself. if i store something on page a, it's not visible in page b's session. if i return to page a, it's there again. sometimes. how can i save attributes in a way that stores them in the "real session" across all pages?

is the session i get via getThreadLocalRequest() depending in the current thread? if yes how to get the actual session?

Jens

unread,
Aug 13, 2011, 9:21:08 AM8/13/11
to google-we...@googlegroups.com
getThreadLocalRequest().getSession() gives you the real/actual HttpSession of your application server. As long as you visit page a and page b from the same browser instance you have the same session. So you probably have a different problem.

I don't know your servlet code but keep in mind that you have to work with session attribute values in a thread safe manner. Session.getAttribute() and Session.setAttribute() are thread safe but your servlet is not as it can be executed by several threads in parallel (depending on the number of parallel requests).

Also check that you do not have multiple session cookies for the same domain and path for some reason and that, if you use clustering, your session replication is working correctly.
Reply all
Reply to author
Forward
0 new messages