The servlets run by a program called TOMCAT. TOMCAT runs on birch.wellesley.edu and uses the port 8080. Servlets are orgainzed into web applications. A web application may include Java classes, Java .jar files, images, and so on. To access a servlet, one needs to specify the application to which the servlet belongs. For instance, if you type
http://birch.wellesley.edu:8080/examples/servlet/MySession1
in your browser, this you are accessing a servlet
MySession1 in the web application examples.
When a request for a servlet is made, TOMCAT checks if the servlet with this class is already running. If the servlet is already running and its class has not changed since the last access, then the request is forwarded to the servlet. If its class has changed or the servlet is not running, then its class is started.
images, which contains .gif and .jpg files used by the
servlets. See the "ice cream shop with graphics" example here to
see how to use an image in a servlet.
WEB-INF, which contains:
classes for all java classes used in
the application. They include all the servlet classes and other Java
classes used by the servlets. For instance, the web application
examples contains, among others, files IceCream1.class
and KillSession.class (the two servlets in the ice cream shop
application), and also the file Order.class (the java class used by
these servlets). Even though you may put .java files in this
directory, they don't have to be there. You will copy your servlet
classes into this directory
lib for all .jar files used in the
application. Your application has mckoidb.jar file in its
lib directory. Once a .jar file is placed in this
directory, all servlets can automatically access it.
web.xml: the file that describes your web
application. In this assignment we don't need to do anything with this
file, but we might need to modify it in the future.
servlets in a web application
directory has nothing to do with the classes of servlets. You will not
need to access it.
A web application with your project login name has been created for
each project group. The directory is
/etc/tomcat3/conf/jakarta-tomcat-3.3a/webapps/myproj on
birch.wellesley.edu. Instead of myproj you will use your project login
name.
To compile the servlet, type
javacee MyGreatServlet.java
If it uses other classes, you can compile them all together as
javacee MyGreatServlet.java MyHelperClass.java
or separately. Files MyGreatServlet.class and MyHelperClass.class will
be created if the compilation is successful.
Servlets are supported in Java 2 Enterprise Edition (J2EE). So far you
have been working with Java 2 Standard Edition.
javacee is a variation of the Java compiler
javac which includes J2EE libraries.
Note that the abbreviation javacee exists only on puma
(including puma hosts, s.a. lion, tiger, etc.) and on birch, but not
on other Wellesley machines and not outside of Wellesley.
To "run" your servlet, you need to copy its class(es) to the directory
/etc/tomcat3/conf/jakarta-tomcat-3.3a/webapps/myproj/WEB-INF/classes
on birch. Actually, your puma account is accessible on birch with the
same password as on puma. Files are shared between puma and birch, so
all your file changes on puma will immediately take affect on birch,
too.
To copy the class files, you need to:
ssh birch
will connect you to birch with your current login name. You may get the
following warning:
The authenticity of host 'birch (149.130.13.127)' can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)?
Type yes (all three letters).
cp MyGreatServlet.class /etc/tomcat3/conf/jakarta-tomcat-3.3a/webapps/myproj/WEB-INF/classes/.
Instead of MyGreatServlet.class use the name of your servlet, and
instead of myproj use the login name of your project.
http://birch.wellesley.edu:8080/myproj/servlet/MyGreatServlet
in your browser (you may omit .wellesley.edu)
to test your servlet. Copy other classes used by the servlet if they
have been recompiled.