Java Reference
In-Depth Information
L ISTING 7.11
Continued
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// If we get a GET request, pass the request/response to
// the doPost() method
doPost(request, response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<html>\n<body>\n<table border=\”1\” width=\”100%\”>”);
Connection con = null;
ConnectionPool pool = null;
try {
// Get a reference to the ConnectionPool from the Global
// ServletContext
pool =(ConnectionPool)
getServletContext().getAttribute(“CONNECTION_POOL”);
// Get a connection from the ConnectionPool
con = pool.getConnection();
if ( con != null ) {
// Create the statement
Statement statement = con.createStatement();
// Use the created statement to SELECT the DATA
// FROM the Titles Table.
ResultSet rs = statement.executeQuery(“SELECT * “ +
“FROM Titles”);
Search WWH ::




Custom Search