Andreas Rozek Hints for Reading List of Recent Changes Guestbook Entry Contact the Author  Deutsche Version  HomePage Previous Topic Next Topic  First Page of Current Topic Next Page Previous Page

Java Servlets - Programming Experiments

The links listed below refer to the author's initial experiments with Java Servlets. For the links to work properly (in a local environment) the following requirements have to be met:

  • a web server with support for servlets has to be running on the local host under port number 9090 (the author is using Gefion's LiteWebServer 2.2.1 for that purpose);

  • if the default servlet invocation mechanism foreseen by the LiteWebServer has been disabled (e.g., for security reasons), any of the servlets shown below have to be configured explicitly;

  • all servlets (and any additional files which may be needed for a proper servlet execution) have to be installed in a subdirectory where they can be found by the server. A list of all these files can be found at the end of this page.

Please, also consider my "Hints for Reading" and the "List of Recent Changes".

LiteWebServer Configuration

The following modifications have to be applied to the given files in order to instruct the LiteWebServer to invoke a servlet whenever requested:

(installdir)/config/rules.properties
add the following lines:
  /Servlet_00=Servlet_00
  /Servlet_01=Servlet_01
  /Servlet_02=Servlet_02
  /Servlet_03=Servlet_03
  /Servlet_04=Servlet_04

These modifications instruct the LiteWebServer to invoke on of the given servlets whenever the URI of an HTTP request starts with the corresponding prefix. It is also assumed that the default rule

  /=file

is still active;

(installdir)/config/servlets.properties
add the following lines:
  servlet.Servlet_00.code=Servlet_00
  servlet.Servlet_01.code=Servlet_01
  servlet.Servlet_02.code=Servlet_02
  servlet.Servlet_03.code=Servlet_03
  servlet.Servlet_04.code=Servlet_04

These modifications associate a concrete servlet class with a given servlet name;

In both cases, (installdir) has to be replaced by the access path for the installation directory of LiteWebServer on your local system.

Using a configuration as shown above, any servlet class files will have to be copied into (installdir)/servlets/ and all associated data files into (installdir)/html/default. Again, (installdir) denotes the LiteWebServer installation directory.

Do not forget to restart LiteWebServer whenever any of the servlet class files has changed. Otherwise, these changes will not have any effect.

Servlet Experiments

After this initial preparation, following the links shown below should work as foreseen. Please note, that you cannot test the following links over the internet - you must install a (servlet capable) HTTP server locally (as described above)!

  • Servlet_00 - first experiments with Java Servlets (Output Example)
    the first "experiment" demonstrates some basic programming techniques for servlets: it creates a simple HTML document (using numerous "println" statements) which contains a table with the values of several "CGI variables";

  • Servlet_01 - displays the contents of several "CGI variables" (Output 1, 2)
    when invoked without any parameters (within the HTTP "Get" request), "Servlet_01" responds with a HTML document that (is loaded from disk and) contains a form with numerous input elements and a "submit" button, which sends the actual state of all these input elements back to the server. Now, "Servlet_01" examines any given request parameters and returns a HTML file with a table of their values;

  • Servlet_02 - lists all HTTP request headers (Output Example)
    "Servlet_02" creates a HTML document with any headers sent along with a given HTTP request;

Note: from time to time, image files which belong to the HTML documents sent as the response to a HTTP request get "lost" and will then not be shown by the browser. Presumably, this issue is due to the simplicity of the abovementioned servlets (which are unable to handle several requests simultaneously). Just resubmit your request and - with a little bit of luck - you will get the foreseen result.

Required Files

In order to run the experiments shown above, the following files have to be installed into the default "document" (or the "servlet") directory of your LiteWebServer:

References

[1] Sun Microsystems, Inc.
Java Servlet Technology
(see http://java.sun.com/products/servlet/index.html)
[2] Cynthia Bloch, Stephanie Bodoff
The Servlet Trail of The Java Tutorial
(see http://java.sun.com/docs/books/tutorial/servlets/index.html)

Disclaimer

Please, consider also the author's Disclaimer!

http://www.Andreas-Rozek.de/JavaServlets/index.html    (last Modification: 31.07.2002)