Lab 5 - Deploying A Simple Servlet
Lab 5 - Deploying A Simple Servlet
Materials:
PC with Java SDK and JCreator installed.
PC with Java EE SDK 5.03 installed.
PC with Apache Tomcat installed and configured
Write a servlet that generates a dynamic quote of the day. This servlet generates a dynamic HTTP
response by selecting a random quote of the day. You might want to use a constant array of strings to
hold the messages and then at runtime generate a random number based on the number of elements in
the array.
<HTML>
<HEAD><TITLE>Quote of the Day Servlet</TITLE></HEAD>
<BODY BGCOLOR=’white’>
The quote of the day is:<BR>
<H3>the message</H3>
</BODY>
</HTML>
G.) In JCreator, add the javaee.jar in the project library. The javaee.jar file can be found at the
C:\j2ee_5.0\lib, assuming that the j2ee_5.0 is the installation directory of Java EE SDK.
H.) Compile the QuoteServlet.java and store the .class file in webapps/ROOT/WEB-
INF/classes/adprog1/web/ folder inside the installation directory of Apache Tomcat.
I.) When the servlet class has been deployed and the Apache Tomcat has been started, you can activate
the servlet using a Web browser. Verify that you can start the server. Double-click
install_dir/bin/startup.bat and try accessing http://localhost/.
J.) Launch the Web browser and enter the URL for the servlet in the Address field. The URL for this
servlet is:
http://localhost:8080/servlet/adprog1.web.QuoteServlet
HINTS:
Listed below are hints that might help you to complete this exercise.
o Use the Math.random method to generate a random double number between 0.0 and 1.0. Transform
this result to get an integer between 0 and N with code such as:
(int) (Math.random() * N)
o You might want to store the set of messages in a static array. An array can be initialized with the
following syntax: