tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Help - Example of RequestDispatcher call.
Date Mon, 09 Oct 2000 15:55:59 GMT
"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




Mime
View raw message