Java Reference
In-Depth Information
L ISTING 22.1
Continued
// Set the Username
pool.setUsername(“”);
// 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(“TRADER_POOL”, pool);
System.err.println(“ADDED TRADER_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(“TRADER_POOL”);
Search WWH ::




Custom Search