tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <wbar...@wilshire.com>
Subject Re: static method to get servlet context
Date Mon, 12 May 2008 01:37:57 GMT

"Nilesh Bansal" <nileshbansal@gmail.com> wrote in message 
news:f36128690805111357u526d2c52h61b3a54b3faae380@mail.gmail.com...
> hi all,
>
> I want to know if Tomcat (servlet api) provides some way by which a
> Java method can get session information or page context associated
> with the current executing thread?
>
The short answer is no:  Tomcat out-of-the-box doesn't provide this type of 
functionality

> Inside a JSP or a class implementing HttpServlet, one can easily get
> the page context and session information. But is there some static
> helper function which can return the same information for the current
> executing thread? I don't want to pass the pageContext as an
> additional variable to all method calls in JSP.
>
Long answer:  There is nothing to prevent you from creating you a static 
ThreadLocal and storing whatever information you need in that.  If you don't 
actually need the pageContext, then a simple Filter could be used to set 
this information up.

> DWR for example provides the following for all DWR requests:
> WebContext webContext = WebContextFactory.get();  // get() is a static 
> function
> HttpSession session = webContext.getHttpServletRequest().getSession();
>
> thanks
> Nilesh
>
> -- 
> Nilesh Bansal
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message