Java Reference
In-Depth Information
It takes a string that represents the key that was used to add the object in the setAttribute()
method, and returns a reference to an object. You must downcast the object back to a
ConnectionPool because when it was stored in the ServletContext , it was stored as an object.
The destroy() method then empties the ConnectionPool and removes the attribute from the
ServletContext using the removeAttribute() method. The destroy() method is listed in the
public void destroy() {
// Access the ServletContext using the getAttribute()
// method, which returns a reference to the ConnectionPool.
ServletContext context = getServletContext();
ConnectionPool pool =
if ( pool != null ) {
// empty the pool
// Remove the Attribute from the ServletContext
else {
System.err.println(“Could not get a reference to Pool!”);
You might want to set up the ConnectionPoolServlet as a preloaded servlet. This will
make sure that the connections are already available before the first request is made.
You can do this by including the following lines in your web.xml file:
Search WWH ::

Custom Search