struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Newfield <d...@newfield.org>
Subject Re: Session object null
Date Tue, 18 May 2010 16:49:44 GMT
On 5/18/10 12:35 PM, Ken wrote:
> What I don't understand is I have an object who's constructor needs
> session data...
> So it calls:
> Map session = ActionContext.getContext().getSession();
>
> But session is always null...

http://struts.apache.org/2.1.8.1/struts2-core/apidocs/com/opensymphony/xwork2/ActionContext.html#getContext()

Explains that this static method works by looking up the value in a 
ThreadLocal: "Returns the ActionContext specific to the current thread."

So if that constructor is happening within the same thread in which the 
request was originally being processed, and after xwork finishes setting 
up that context, it should work:

"The ActionContext is thread local which means that values stored in the 
ActionContext are unique per thread. See the ThreadLocal class for more 
information."

But random code in a random thread occurring at a random time cannot 
rely on ActionContext.getContext().

I'd check out the *Aware interfaces if I were you.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message