0% found this document useful (0 votes)
121 views

Lab 6 - Developing A Servlet Using HTML Forms

This document provides instructions for developing a servlet using HTML forms to conduct an online survey for a bookstore. Students will create an HTML form with input fields to collect customer information and survey responses. They will then develop a BookstoreSurvey servlet to retrieve the form data and display it in an HTML table. Finally, students will deploy the servlet in Tomcat and activate it using a web browser to test that the form data is properly processed and displayed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Lab 6 - Developing A Servlet Using HTML Forms

This document provides instructions for developing a servlet using HTML forms to conduct an online survey for a bookstore. Students will create an HTML form with input fields to collect customer information and survey responses. They will then develop a BookstoreSurvey servlet to retrieve the form data and display it in an HTML table. Finally, students will deploy the servlet in Tomcat and activate it using a web browser to test that the form data is properly processed and displayed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

F0102

Laboratory Exercise 6: Developing a Servlet


Using HTML Forms

At the end of the exercise, the students should be able to:


 Develop a servlet using HTML forms
 Deploy a servlet in the Web container

Materials:
 PC with Java SDK and JCreator installed.
 PC with J2EE 1.3 installed
 PC with Apache Tomcat installed and configured

Perform the following instructions:

Case Problem: The owners of Goodwill Bookstore are considering developing a Web site for online book
buying. They want to survey college students to find out whether Internet shopping is feasible for their
products. They want you to create a Web page that contains the question as shown in the figure below.

Laboratory Exercise 6: Developing a Servlet Using HTML Forms * Property of STI


Page 1 of 4
F0102

Instructions:

Part 1 - Developing the "bookstore message" HTML Form.

1. Start a new HTML file survey.html using JCreator. In the title tag, write ’Lab 6 - Devloping
Servlet Using HTML Forms’.
2. Begin the form processing structure by using the POST method with the ACTION attribute set to
/servlet/adprog1.web.BookstoreSurvey.
3. Create a H1 heading for the title.
4. Insert in the first row text fields for first name, last name and email address. Refer to the table
below for the attribute values.
5. Insert in the second row a text field for an address. Refer to the table below for the attribute values.
6. Insert in the third row text fields to contain city, country and ZIP code. Refer to the table below for
the attribute values.
7. Create radio buttons for the next survey question. Refer to the table below for the attribute values.
8. In the next row create a selection menu with the first option (Goodwill Bookstore) plus three other
options. Refer to the table below for the attribute values.
9. Insert a second radio button for the next question. Refer to the table below for the attribute values.
10. Specify a five-row, 75-column text area field for the input. Refer to the table below for the attribute
values.
11. Create Submit and Reset buttons at the bottom of the Web page form.
12. Save the file.

Form Element Name Value


Firstname Text Field required-firstname (none)
Lastname Text Field required-lastname (none)
Email Text Field required-email (none)
Address Text Field address (none)
City Text Field city (none)
Country Text Field country (none)
Zip Text Field zip (none)
Yes
Question 1 Radio Button question1
No
Goodwill Bookstore
National Bookstore
Question 2 Select Field question2
PowerBooks
Book for Less
Question 3 Radio Button question3 Yes

Laboratory Exercise 6: Developing a Servlet Using HTML Forms * Property of STI


Page 2 of 4
F0102

No
Question 4 TextArea question4 (none)
Submit Button Submit Submit
Reset Button Reset Reset

Part 2 - Developing the BookstoreSurvey Servlet

1. Write the BookstoreSurvey servlet program that will retrieve form data and create an on-the-fly
HTML page that displays the contents in a table.
2. The sample response should look like the one shown in Figure 1.

Part 3 - Deploying and Activating the BookstoreSurvey Servlet

1. Compile the BookstoreSurveyServlet.java and store the .class file in webapps/ROOT/WEB-


INF/classes/adprog1/web/ folder inside the installation directory of Apache Tomcat.
2. When the servlet class has been deployed and the Apache Tomcat has been started, you can
activate the servlet using a Web browser.
3. Launch the Web browser and enter the URL for the servlet in the Address field. The URL for this
servlet is:

http://localhost:8080/survey.html

4. Enter data and click the Submit button. The servlet should respond and displays the form data in a
table (see sample output below).

Bookstore Survey Result

Firstname: Allan
Lastname: Abulencia
Email: [email protected]
Address: Smart Tower, Ayala Ave., Makati City
City: Makati
Country: Philippines
Zip Code: 1020
Question 1: Yes

Laboratory Exercise 6: Developing a Servlet Using HTML Forms * Property of STI


Page 3 of 4
F0102

Question 2: National Bookstore


Question 3: No
Question 4: no comment

Figure 1: Sample Output

Laboratory Exercise 6: Developing a Servlet Using HTML Forms * Property of STI


Page 4 of 4

You might also like