% gunzip Jetty_compact.tar.gz
% tar -xvf Jetty_compact.tar
This will create a subdirectory with the Jetty server.
setenv JETTY_HOME /home/joe/java/Jetty-3.0.1
This is what you would do in tcsh. In ksh, enter the
following line in your .profile:
export JETTY_HOME=/home/joe/java/Jetty-3.0.1
setenv CLASSPATH ${CLASSPATH}:${JETTY_HOME}/lib/javax.servlet.jar
setenv CLASSPATH ${CLASSPATH}:${JETTY_HOME}/lib/com.mortbay.jetty.jar
setenv CLASSPATH ${CLASSPATH}:${JETTY_HOME}/lib/com.microstar.xml.jar
Now you are ready to run Jetty and test a servlet.
First, we will run Jetty and try a default servlet:
Now you are ready to type, compile and run your own servlet:
java com.mortbay.Jetty.Demo
Did it run? Did you remember to log in and out to re-set your CLASSPATH?
Let's take this one step further:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class HelloWorld extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// Set the content type of the response.
resp.setContentType ("text/html");
// Create a PrintWriter to write the response.
java.io.PrintWriter out = new PrintWriter (resp.getOutputStream());
// The first part of the response.
out.println ("");
out.println ("
% javac HelloWorld.java
% cp HelloWorld.class $JETTY_HOME/servlets/.
http://localhost:8019/servlet/HelloWorld
<html>
<head><title> test </title></head>
<body>
<a href="http://localhost:8502/servlets/HelloWorld"> Click
here for a classic greeting </a>
</body>
</html>
and save it in the docroot directory.