Creating and Deploying Servlets
We will be using the TomCat webserver extension for Servlets. Because most
universities do not allow servlets (at this writing), you will need to
download a webserver extension application to your pc, compile servlets
there and then launch them. The following tells you how!
- Installing Tomcat
- Download and install jakarta-tomcat-4.0.1.exe from
http://jakarta.apache.org/builds/jakarta-tomcat-4.0/archives/v4.0.1/bin/
- Starting Tomcat
- Go to the directory C:\Windows\Start Menu \Apache Tomcat4.0
and click on the Start Tomcat icon
(Or you can click on Start -> Programs ->Apache Tomcat 4.0 -> Start Tomcat)
- Now, with Tomcat running, type the following URL into your
browser and view documentation and examples:
http://localhost:8080
(If "localhost" doesn't work, try "127.0.0.1")
- You can stop Tomcat by clicking on the Stop Tomcat icon
in C:\Windows\Start Menu \Apache Tomcat4.0
(Or you can click on Start -> Programs ->Apache Tomcat 4.0 -> Stop Tomcat)
- Compiling servlets. Servlets are essentially java programs with
two new includes:
import javax.servlet.*;
import javax.servlet.http.*;
- Save your .java file somewhere
- Open a DOS window
- To compile either
- Running Servlets
- Copy your servlet .class file to the directory:
C:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\
- Restart your Tomcat server (First "Stop TomCat" - see above).
Everytime you put
a new servlet in the directory, you must restart the Tomcat server
- Either: