Computer Science 396S
Assignment 4
Due:
Either download
the Apache Tomcat server from http://jakarta.apache.org/tomcat/tomcat-4.0-doc/
or my website and configure it. See the
document explaining how to do this for details.
If you are unable to use Tomcat on your own computer, you may use
computers in the tutoring lab on the second floor of
When you have Tomcat working, try it out with a simple servlet such as HelloServlet below.
package hello;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// HelloServlet is used to
echo a name and say hello.
public class HelloServlet extends HttpServlet
{
public void doGet (HttpServletRequest
request, HttpServletResponse response)
{
try
{
// Get a PrintWriter and set up the output
page.
PrintWriter out = response.getWriter ();
// Page is the same class that was used with
the WebServer.
Page.createHeader (out, "Hello");
// Get the name from the request and echo it.
String name = request.getParameter
("name");
out.println ("<h3>Hello
" + name + "</h3>");
Page.createFooter (out);
} catch (IOException ex) {System.out.println ("IO
Exception.");}
} // doGet
} // HelloServlet
You can use the following
html form to access the servlet.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<html>
<head><title>Hello
Example</title>
</head>
<body>
<h3>Please enter your
name.</h3>
<form name = "hello" method =
"get"
action="http://localhost/servlet/hello.HelloServlet">
<input type = "text" name =
"name" size = "15" /> Name
<p><input type="submit"
value="Submit"></p>
</form>
</body>
</html>
Make sure that the html form
is in the ROOT folder and the servlet is in the classes
folder. Compile the servlet so that the
class file will be in the hello subfolder of the classes
folder.
When you have this working
properly, adapt the programs that you wrote for assignment 3 so that they now
work with Tomcat. You will have to add
several import statements, change the process method to a doget method, and add
HttpServlet to the method parameters.
Also change the html file so that it now refers to the servlet rather
than to the processor file.
Next create another servlet
and html file that either inserts, deletes, or updates a row in your
database. Hand in the code for the html
files and servlets.