Java Reference
In-Depth Information
8 Tracing the init() and destroy() Servlet Methods
Start TextPad and open the WebStocks.java file. Insert a new line at the
beginning of the init() method and then type System.out.println ("Opening
a connection to the database") ; on that line. Insert a new line at the begin-
ning of the destroy() method and then type System.out.println("Closing
the database connection ") ; on that line. Compile the servlet and then place
the class file in the Tomcat default servlet folder, or a location specified by your
instructor. Start Tomcat and then log on to the WebStocks Web application. Log
off the WebStocks Web application. Log on and log off again. In the folder,
C:\Program Files\Apache Software Foundation\Tomcat 5.5\logs, locate and open
the text file, stdout_yyyymmdd, where yyyymmdd represents the current year,
month, and day. Scroll to the end of the file. The window should resemble Figure
12-95. Stop Tomcat. Based on the text displayed and your knowledge of the
servlet, answer the following questions:
1. When is a connection to the database opened?
2. How often is a connection made to the database?
3. Once made, when is the connection to the database closed?
FIGURE 12-95
Search WWH ::




Custom Search