Computer Science 396S
Assignment 5
Due: October 18, 2004

Create a web application that can be used with Tomcat.  To begin with, create a subfolder of the webapps folder.  The name of the folder will be the name of your application.  Make sure that the name contains your initials or some other identification so that it doesn’t get mixed up with the work of other students.  Once you have created the folder, add to it the WEB-INF folder and the classes folder.  Put your html file in the top folder, the web.xml file in the WEB-INF folder and your Java files in the classes folder.  Use packages, so that when you compile your Java files the class files will be in a subfolder of the classes folder.

Your application will consist of an html file in your main folder, the web.xml file in the WEB-INF folder and at least four Java servlets in the classes folder.  Use the three servlets written for Assignment 4 and add one more.  The new one should do an additional operation using one of the SQL commands, Insert, Update, or Delete  Choose one that you did not use before.

After you create the servlets, set up the web.xml file.  If you are using Tomcat version 4, the file contains the following:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
</web-app>

Fill in the information between the two <web-app> tags.  Follow the form in the document called Configuring Tomcat for a Web Application.  Tomcat version 5 uses schema and is set up in a somewhat different fashion.

Once all the servlets have been compiled and the web.xml file created, you can run your application.  After starting Tomcat, use your browser to access the application.  If you called the folder bookstore, it will be accessed by
     http://localhost/bookstore/
or
     http://localhost:8080/bookstore/
depending upon whether or not you changed the port to 80 from 8080.

Use the welcome file tags to indicate the home web-page for your application.  This page is often called index.html, but other names can be used.  Whatever name you use should be in the welcome file list.
     <welcome-file-list>
          <welcome-file>index.html</welcome-file>
     </welcome-file-list>
This tells Tomcat where to start your application.

If the <servlet-mapping> tags are correct, your action statements are also much briefer.  For example, if you have a DisplayBooks servlet, and your web.xml file contains both

     <servlet>
          <servlet-name>DisplayBooks</servlet-name>
          <servlet-class>library.DisplayBooks</servlet-class>
     </servlet>
and
     <servlet-mapping>
          <servlet-name>DisplayBooks</servlet-name>
          <url-pattern>/display/*</url-pattern>
     </servlet-mapping>
your html form is just
     <form name = "display" method = "get" action = "../bookstore/display">
          <p><input type="submit" value="Send"></p>
     </form>

Setting up a web application is very helpful.  It keeps all the related files in one subfolder of the webapps folder.  Having them all in one place makes it easier to find what you need when you are working on the application.  And to hand it in, just zip up the folder (with all its files) and either hand it in on a disk or email it to me.