Java Reference
In-Depth Information
L ISTING 20.1
Continued
// Set the Password
pool.setPassword(“”);
// Initialize the pool
pool.initializePool();
// Once the pool is Initialized, add it to the
// Global ServletContext. This makes it available
// To other servlets using the same ServletContext.
ServletContext context = getServletContext();
context.setAttribute(“CATALOG_POOL”, pool);
System.err.println(“ADDED CATALOG_POOL”);
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Set the response content-type
response.setContentType(“text/html”);
// get the Writer object
PrintWriter out = response.getWriter();
out.println(“This Servlet does not service requests!”);
out.close();
}
public void destroy() {
// Access the ServletContext using the getAttribute()
// method, which returns a reference to the ConnectionPool.
ServletContext context = getServletContext();
ConnectionPool pool =
(ConnectionPool)
context.getAttribute(“CATALOG_POOL”);
if ( pool != null ) {
// empty the pool
pool.emptyPool();
// Remove the Attribute from the ServletContext
context.removeAttribute(“CATALOG_POOL”);
}
else {
Search WWH ::




Custom Search