Define the middle tier for the Road Sign Review application.

a) Opening roadSigns.jsp. Open the roadSigns.jsp that you modified
b) Displaying road sign images. In the roadSigns.jsp source code, add a while statement to roadSigns.jsp. The loop should obtain the image file name and image name from each row in the ResultSet and use them to insert an img element in the page. Note that the loop replaces the long list of image elements that you added to this JSP . The remaining img element will appear as literal HTML markup between the two scriptlets that start and end the while statement. Two JSP expressions should be used to obtain the image file name and image name from the ResultSet.
c) Closing the ResultSet. In the second scriptlet and after the while statement, add code to close the ResultSet invoking its close method.
d) Defining the form’s method and action attributes in the states.jsp page. In the roadSigns.jsp source code, specify "post" as the form element’s method and use the action attribute to forward the client request to roadTestRegistered.jsp.
e) Saving the file. Save your modified source code file.
f) Opening roadTestRegistered.jsp. Open the roadTestRegistered.jsp file that you created in Exercise 1.13.
g) Displaying the client’s name. In the roadTestRegistered.jsp source code, modify the paragraph element that contains “confirmation” to use a JSP expression to obtain the client’s name from the JSP implicit object request and display it in the paragraph.
h) Displaying the client’s phone number. Modify the paragraph element from the previ- ous step to use a JSP expression to obtain the client’s phone number from the JSP implicit object request and display it in the paragraph.
i) Saving the file. Save your modified source code file.
j) Copying roadSigns.jsp and roadTestRegistered.jsp to the RoadSign directory.
Copy your updated roadSigns.jsp and roadTestRegistered.jsp files and paste
them into the C:\Program Files\Apache Group\Tomcat 4.1\webapps\RoadSign
directory.
k) Starting Tomcat. Select Start > Programs > Apache Tomcat 4.1 > Start Tomcat to start the Tomcat server.
l) Testing the application. Open a Web browser and enter the URL http:// localhost:8080/RoadSign/roadSigns.jsp, enter your name and phone number, and click the Register button to test the application.
m)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 Road Signs
13
14
15
16
17

Road Signs


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:roadsigns" );
34
35 // obtain road sign information
36 if ( connection != null )
37 {
38 // create statement
39 Statement statement = connection.createStatement(
40
41 // execute query to get road sign information
42 ResultSet results = statement.executeQuery(
43 "SELECT * FROM signs" );
44
45 // get all signs from database
46 while ( results.next() == true )
47 {
48 %> <%-- end scriptlet to insert HTML --%>
49
50
51 " alt =
53 "<%= results.getString( "name" ) %> sign">
54
55 <% // continue scriptlet
56
57 } // end while loop
58
59 results.close(); // close result set
60 connection.close(); // close database connection
61
62 } // end if
63
64 } // end try
65
66 // catch
67 catch( SQLException exception )
68 {
69 out.println( "Exception: " + exception + " occurred." );
70 }
71
72 %> <%-- end scriptlet --%>
73
74
= "post" action = "roadTestRegistered.jsp">
76
77

Register for your driving test


78
79
80

Name:


81
82
83

Phone Number:
84
85


86
87
88


89
90
91
92
93
```

```
1
5
6
7
8
9 Road Test Registration
10
11
12
13
14

Registration Complete


15
16


17 Thank you, <%= request.getParameter( "name" ) %>.
18 We will contact you shortly at
19 <%= request.getParameter( "phoneNumber" ) %>.
20


21
22
23
```

Computer Science & Information Technology

You might also like to view...

Which of the following is NOT a step to reduce the amount of spam you receive?

A. Reply to spam when you receive it. B. Don't click links in e-mail messages, even if it's an opt-out link. C. If your e-mail provider offers a way to report spam, use it. D. When spam gets out of hand, consider changing your e-mail account so that you have a different e-mail address.

Computer Science & Information Technology

Round the values down at the places noted.

299 at hundreds place

Computer Science & Information Technology