(Phone Book Application: Functionality) Define the middle tier for the Phone Book application.

a) Opening phoneBook.jsp. Open the phoneBook.jsp file that you modified.
b) Defining the form’s method and action attributes in the phoneBook.jsp page. In the phoneBook.jsp source code, specify "post" as the form element’s method and use the action attribute to forward the client request to phoneNumber.jsp.
c) Populating the HTML menu control with names. In the phoneBook.jsp source code, add a while statement to the scriptlet in phoneBook.jsp. The loop should add each person’s name (retrieved from the ResultSet) to the HTML menu control. This step requires literal HTML markup and a JSP expression as well.
d) Closing the ResultSet. In the scriptlet that ends the while statement, add code to close the ResultSet by invoking its close method.
e) Saving the file. Save your modified source code file.
f) Opening phoneNumber.jsp. Open the phoneNumber.jsp file that you modified in
Exercise 31.11.
g) Displaying the selected name. In the phoneNumber.jsp source code, modify the h1 header element to display the selected name that is received as part of the client request.
h) Displaying the phone number. In the phoneNumber.jsp source code, modify the HTML paragraph element that contains “numbers” to display the phone number that corresponds to the selected name. Note that you need to move the cursor to the first row of the ResultSet to retrieve the phone number.
i) Closing the ResultSet. In the scriptlet that appears after the code you added in
Step h, add code to close the ResultSet by invoking its close method.
j) Saving the file. Save your modified source code file.
k) Copying phoneBook.jsp and phoneNumber.jsp to the PhoneBook directory. Copy your updated phoneBook.jsp and phoneNumber.jsp files and paste them into the C:\Program Files\Apache Group\Tomcat 4.1\webapps\PhoneBook directory.
l) Starting Tomcat. Select Start > Programs > Apache Tomcat 4.1 > Start Tomcat to start the Tomcat server.
m)Testing the application. Open a Web browser and enter the URL http:// localhost:8080/PhoneBook/phoneBook.jsp, select a name from the list and click the Get Number button to test the application.
n) Stopping Tomcat. Select Start > Programs > Apache Tomcat 4.1 > Stop Tomcat to stop the Tomcat server.


```
1
2
3
4 <%-- import java.sql.* for database classes --%>
5 <%@ page import = "java.sql.*" %>
6
7
8
9
10
11
12 Phone Book
13
14
15
16
17

Phone Book Web Application


18
19
20

21
22

Select a name from the list and click
23 the Get Number button


24
25
26
89
90
91


92

93
94
95
```

```
1
2
3
4 <%-- import java.sql.* for database classes --%>
5 <%@ page import = "java.sql.*" %>
6
7
8
9
10
11
12 Phone Number
13
14
15
16
17

<%= request.getParameter( "personName" ) %>


18
19 <%-- begin JSP scriptlet to connect to a database --%>
20 <%
21 // setup database connection
22 try
23 {
24 // specify database location
25 System.setProperty( "db2j.system.home",
26 "C:\\Examples\\Tutorial31\\Exercises\\Databases" );
27
28 // load Cloudscape driver
29 Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" );
30
31 // connect to database
32 Connection connection = DriverManager.getConnection(
33 "jdbc:db2j:phonebook" );
34
35 // obtain information from database
36 if ( connection != null )
37 {
38 // create statement
39 Statement statement = connection.createStatement();
40
41 // execute query to get all information
42 ResultSet results = statement.executeQuery(
43 "SELECT * FROM phoneNumbers WHERE name = '" +
44 request.getParameter( "personName" ) + "'" );
45
46 results.next(); // move cursor to the first row
47
48 %> <%-- end scriptlet to insert HTML --%>
49
50

<%= results.getString( "phoneNumber" ) %>


51
52
53

Phone Book


54
55 <% // continue scriptlet
56
57 results.close(); // close result set
58 connection.close(); // close database connection
59
60 } // end if
61
62 } // end try
63
64 // catch SQLException
65 catch( SQLException exception )
66 {
67 out.println( "Exception: " + exception + " occurred." );
68 }
69
70 %> <%-- end scriptlet --%>
71
72
73
```

Computer Science & Information Technology

You might also like to view...

Identify the letter of the choice that best matches the phrase or definition.

A. Built-in function that calculates the payments for a loan based on constant payments and a constant interest rate B. Class that provides standard math procedures required for mathematical calculations C. Math class method that returns the absolute value of a number D. Math class method that will raise a number to a power E. Method of the Math class that returns the smaller of two numbers F. Math class constant that is the natural exponent

Computer Science & Information Technology

802.1X combines RADIUS-style AAA with which of the following to make a complete authentication solution?

A. PPP B. MS-CHAP C. EAP D. TLS

Computer Science & Information Technology

A technician is installing a rack mounted server into a rack in a datacenter with CRAC units and blanking panels. Blanking panels are used to:

A. lower the UPS power requirements. B. limit airflow leakage in the rack. C. limit the amount of servers that will fit into the rack. D. color match the server color.

Computer Science & Information Technology

1A is an example of a cell reference.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology