Document last updated 14 April 2001. We are very interested in feedback that would make these materials better. Feel free to write the author, Jonathan Revusky.

Este documento en español
Ce document en français

Building and running the mini-rolodex example

This example assumes that you have already gone through the first 2 servlet examples: Hello, Niggle and the Guestbook. Again, we will reuse the same niggletut web application context that we created for the helloniggle servlet.

Also, in terms of compiling our code, we can reuse verbatim the command that we used to compile the last example. On unix this was:

javac -classpath <libs>/niggle.jar:<libs>/servlet.jar *.java

and on Windows:

javac -classpath <libs>\niggle.jar;<libs>\servlet.jar *.java

where you replace <libs> with the directory where the libraries are located.

Now, one little detail is that we want to be sure that we have specified a location for our data (in this example, we actually do store data!) to an appropriate, feasible location. Open up the the datasources.xml file. There, you will see a line that is:

<PROPERTY KEY="STORE" VALUE="/tmp/rolodex_data" />

Though many users will be able to get away with leaving the line as is, you should make sure that the VALUE attribute points to a location that is writable on your system. For example, on a Windows system, you might want to change the "/tmp" to "C:\windows\temp" or whatever is the appropriate location for temporary files.

After this, you need to make sure you have done the following steps:

  1. Copy the files niggle.jar, freemarker.jar, and xerces.jar into the directory: $TOMCAT_HOME/webapps/niggletut/WEB-INF/lib.
  2. Copy the .class files you generated to the $TOMCAT_HOME/webapps/niggletut/WEB-INF/classes directory.
  3. Copy the page templates, entries.nhtml, ack.nhtml and edit.nhtml, to the same directory as in the last step: WEB-INF/classes.
  4. Copy the data specification files, recorddefs.xml and datasources.xml, to the same directory as the class files and page template files.
  5. You also need to copy the web.xml configuration file to the WEB-INF directory of your web application context.

Testing the servlet

Now we should be able to test the servlet. You should start (or restart, the case being) your server, be it Tomcat or whatever.

Now, if you have looked at the web.xml file, you might have noticed that we added an extra servlet definition: minirolo. So, at this point, you should be able to open the URL:

http://localhost:8080/niggletut/servlet/minirolo

in your browser to run the mini-rolodex app. You can try to add an entry, edit an entry, etcetera. It is a primitive servlet, mind you, with very many possible improvements, but we are getting somewhere!

At this point, you will probably want to read through the notes in which we dissect the various parts of the mini-rolodex example.