You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Len, Peter" <pl...@orionsci.com> on 2000/10/09 17:37:03 UTC

Help - Example of RequestDispatcher call.

Hello,

I am wondering how (or if) RequestDispatcher can help me with my
problem.  I have a servlet (dbServlet) that gets loaded when the Tomcat
starts. It is basically my own database pooler.  Anyway, there are other
servlets that, when called, I want to get ahold of the dbServlet and
obtain a new connection.  After my transaction I will need to inform my
dbServlet to reallocate that connection.  I'm not sure if, or how,
RequestDispatcher.include could get me my connection object and
RequestDispatcher.forward could be used to do the reallocation.

Does anyone know how, or if, I can use RequestDispatcher in this manner?

Thanks,

Peter Len

Re: Help - Example of RequestDispatcher call.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Len, Peter" wrote:

> Hello,
>
> I am wondering how (or if) RequestDispatcher can help me with my
> problem.  I have a servlet (dbServlet) that gets loaded when the Tomcat
> starts. It is basically my own database pooler.  Anyway, there are other
> servlets that, when called, I want to get ahold of the dbServlet and
> obtain a new connection.  After my transaction I will need to inform my
> dbServlet to reallocate that connection.  I'm not sure if, or how,
> RequestDispatcher.include could get me my connection object and
> RequestDispatcher.forward could be used to do the reallocation.
>

You will not be able to get a reference to your pooler servlet itself.
There is no longer any mechanism in the servlet API that makes this
possible.

What you should do, however, is have your pooler servlet store the
connection pool object as a servlet context attribute, like this (in the
initialization code):

    ConnectionPool pool = ... create the pool ...
    getServletContext().setAttribute("pool", pool);

then, in any other servlet in your webapp you can retrieve it like this:

    ConnectionPool pool = (ConnectionPool)
        getServletContext.getAttribute("pool");

or, under JSP pages, it is available as an application-scope bean under the
name "pool".

>
> Does anyone know how, or if, I can use RequestDispatcher in this manner?
>
> Thanks,
>
> Peter Len

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat




Re: Help - Example of RequestDispatcher call.

Posted by kenneth topp <ca...@prodigy.net>.
I would recommend using a singleton pattern.  I have no good internet
pointers to recommend.  but there is some info you can find about
singletons in jguru.

The path you are heading doesn't seem right to me.  (Just one man's
opinion).

Good Luck,

Kenneth Topp


On Mon, 9 Oct 2000, Len, Peter wrote:

> Hello,
> 
> I am wondering how (or if) RequestDispatcher can help me with my
> problem.  I have a servlet (dbServlet) that gets loaded when the Tomcat
> starts. It is basically my own database pooler.  Anyway, there are other
> servlets that, when called, I want to get ahold of the dbServlet and
> obtain a new connection.  After my transaction I will need to inform my
> dbServlet to reallocate that connection.  I'm not sure if, or how,
> RequestDispatcher.include could get me my connection object and
> RequestDispatcher.forward could be used to do the reallocation.
> 
> Does anyone know how, or if, I can use RequestDispatcher in this manner?
> 
> Thanks,
> 
> Peter Len
>