Document last updated January 21, 2001. We are very interested in feedback that would make these materials better. Feel free to write the author, Jonathan Revusky.
This directory contains a minimal "Hello, World" servlet written on top of the Niggle framework. Frankly, it is a silly little example. Our object here is that, once you manage to build and run the minimal servlet here, you will be set up to move on to more involved examples. At the very least, you will have a servlet runner installed and you will have managed to compile and run the minimal Niggle-based servlet. You will be out of the starting gate.
These instructions assume that you have a 1.2 level JDK installed on your machine and that you have installed Tomcat or a servlet container that uses the same configuration scheme. Though these instructions refer to Tomcat, it should not be difficult at all to get this example working with another servlet engine. Though if the servlet engine uses non-standard configuration files, you may have to adapt the instructions.
The trick to compiling the code is to make sure that the compiler can resolve all of the dependencies. To compile this minimal servlet, we need niggle.jar and servlet.jar on the CLASSPATH. In the following, you will have to replace <libs> by the directory where the .jar files are actually located. On a unix machine, the command would be:
javac -classpath <libs>/niggle.jar:<libs>/servlet.jar *.java
javac -classpath <libs>\niggle.jar;<libs>\servlet.jar *.java
At this point, you should have generated the .class files HelloServletInteraction.class and MinimalNiggleServlet.class that we will use further on.
In the following, I'll refer to the root directory of your server distribution as $TOMCAT_HOME. If you do not have a servlet runner installed, you can go to http://jakarta.apache.org and the simplest thing to do is to download the latest stable binary release of Tomcat. You can simply copy the archive into the directory which you want to be the parent directory of the tomcat home directory.
Now, relative to the TOMCAT_HOME location, there is a webapps directory. This is the location
where the tomcat server looks for information related to web applications. Each subdirectory of
$TOMCAT_HOME/webapps is taken to be the parent directory of a webapp context. We will start
by creating our own webapp context by creating a subdirectory called niggletut
.
Now, under the niggletut directory, create a WEB-INF
directory. On unix systems,
case will be important here. That's "WEB-INF" all caps. And under
WEB-INF
, create 2 further subdirectories: classes
and
lib
.
$TOMCAT_HOME | webapps | niggletut | WEB-INF | classes | lib
What you need to do now is the following:
Now comes the moment of truth. Here's what you need to do:
If you are using tomcat, the first step above is achieved by running the startup script in the $TOMCAT_HOME/bin directory. This is either startup.bat or startup.sh, depending on your religious persuasion. (If you already had tomcat running, you had to run shutdown first.)
Since, by default, tomcat runs on port 8080 and maps <web-app-name>/servlet/<servlet-name> to the servlets in a given context, the following URL should do the trick:
http://localhost:8080/niggletut/servlet/helloniggle
At this stage, you should see the Hello, Niggle message. If you went through the above steps using the Tomcat 3.2 server on top of Java 2, it is hard to see what could have gone wrong. On the other hand, if you are trying to get the example working with a different servlet container, the problem is most likely either that the magical incantation contained in web.xml was insufficient somehow and that you need to tweak a line somewhere in your server's configuration for it to be aware of the servlet you added. The other likely problem is that the URL I told you to open above is not quite right and your servlet would run if you opened the URL that it is actually mapped to! Either of the above problems will make it necessary for you to call upon your own superior hacking skills.
Once you have managed to build and run this example, please go through the accompanying notes which dissect the various pieces of the minimal app and explain their function.