Lab 7 - Configuring Servlet Using ServletConfig
Lab 7 - Configuring Servlet Using ServletConfig
Materials:
PC with Java SDK and JCreator installed.
PC with J2EE 5.5 or later installed
PC with Apache Tomcat installed and configured
Part I.
1. Create the following directory structure in the top-level directory, webapps, in the installation directory
of tomcat. The folder names are case sensitive.
2. Modify the BookstoreSurveyServlet so that aside from displaying the results of the survey on-the-fly, it
will also output the servlet initialization parameters. The parameters to be displayed are given in the
table below as name-value pairs:
Name Value
firstname <supply your firstname here>
lastname <supply your lastname here>
section <supply your section here>
date <the date you perform this exercise>
instructor <your instructor’s fullname>
3. Open a text editor. Type the following codes and save the file as ‘web.xml’. Save this file inside the
webapps/ADPROG1_LAB7/WEB-INF directory. Supply the actual values in the <param-value> tag.
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>BookstoreSurveyServlet</servlet-name>
<servlet-class>adprog1.web.BookstoreSurveyServlet</servlet-
class>
<init-param>
<param-name>firstname</param-name>
<param-value><!-- your first name here --></param-value>
</init-param>
<init-param>
<param-name>lastname</param-name>
<servlet-mapping>
<servlet-name>BookstoreSurveyServlet</servlet-name>
<url-pattern>/bookstore</url-pattern>
</servlet-mapping>
</web-app>
1. Modify the BookstoreSurvey servlet program that will retrieve form data, create an on-the-fly HTML
page, retrieve servlet config initialization parameters and display the contents of the form in a table and
the initialization parameters.
2. Modify the survey.html and change the value of the action attribute as specified in the url-pattern
declared in the web.xml above. Rename the survey.html to index.html and save the file in the
webapps/ADPROG1_LAB7 directory.
3. The sample response should look like the one shown in Figure 1.
http://localhost:8080/ADPROG1_LAB7/index.html
Note: The port number varies depending on the port number you specified in the sever.xml.
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