You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nilesh Bansal <ni...@gmail.com> on 2008/05/11 22:57:08 UTC
static method to get servlet context
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?
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.
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
Re: static method to get servlet context
Posted by Nilesh Bansal <ni...@gmail.com>.
Thanks. ThreadLocal is exactly what I am looking for.
-Nilesh
On Sun, May 11, 2008 at 9:37 PM, Bill Barker <wb...@wilshire.com> wrote:
>
> "Nilesh Bansal" <ni...@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
>
>
--
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
Re: static method to get servlet context
Posted by Bill Barker <wb...@wilshire.com>.
"Nilesh Bansal" <ni...@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