Louis Mechery wrote:
> Hi All,
>
> I am new to Java servlet. I have successfully added and loaded a ConnectionPool
>servlet (database.ConnectionServlet) on the java web server 2.0.
> I want to test the connectionServlet using another servlet "TestConnectionServlet".
>But, I get an error "ConnectionServlet not found" while executing the following code.
>Hope some one can answer to my question. Thanks in advance.
As of the servlet 2.1 API (which I'm pretty sure that JWS 2.0 implements), the
"getServlet()" method has been deprecated, and required to return null. This was done
for valid security reasons that are beyond the scope of this discussion. The bottom
line is that it is no longer possible for one servlet to get a reference to an
instance of any other servlet -- so you cannot access another servlet's methods or
instance variables.
If you want to share objects between servlets, an easy way to do so is store them in
the servlet context attributes. For example, in the servlet that initially creates
your connection pool you could do something like this:
ConnectionPool pool = ....; // Create a new pool
getServletContext().setAttribute("connection_pool", pool);
And in every other servlet in your application, whenever you needed to get a
connection, you could do this:
ConnectionPool pool =
(ConnectionPool) getServletContext().getAttribute("connection_pool");
Connection conn =
pool.allocate(); // Or whatever the right call for your pool is
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html