static method to get servlet context

View: New views
3 Messages — Rating Filter:   Alert me  

static method to get servlet context

by Nilesh Bansal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: static method to get servlet context

by Bill Barker-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


"Nilesh Bansal" <nileshbansal@...> wrote in message
news:f36128690805111357u526d2c52h61b3a54b3faae380@......
> 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@...
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>




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


Re: static method to get servlet context

by Nilesh Bansal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks. ThreadLocal is exactly what I am looking for.

-Nilesh

On Sun, May 11, 2008 at 9:37 PM, Bill Barker <wbarker@...> wrote:

>
>  "Nilesh Bansal" <nileshbansal@...> wrote in message
>  news:f36128690805111357u526d2c52h61b3a54b3faae380@......
>
> > 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@...
>  > To unsubscribe, e-mail: users-unsubscribe@...
>  > For additional commands, e-mail: users-help@...
>  >
>  >
>
>
>
>
>  ---------------------------------------------------------------------
>  To start a new topic, e-mail: users@...
>  To unsubscribe, e-mail: users-unsubscribe@...
>  For additional commands, e-mail: users-help@...
>
>



--
Nilesh Bansal

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