Tims Servlet Tutorial

Tutorial Home

  1. What are servlets ?
  2. The Hello World Servlet
  3. Running Servlets
  4. Reading Form Data
  5. Servlet Configuration
  6. Client Side Form Validation
  7. Cookies
  8. Sessions
  9. Authentication
  10. Dynamic Images
  11. Design, Testing, Security
  12. Servlets and Apache
  13. Using Servlets in SOCS

Tutorial Home Page

This tutorial will attempt to explain how to write Java servlets and use them with a real webserver, such as Apache.

In order to use servlets you will need to have the following installed on your system.

If you do not have either of these installed, they can be obtained from Suns Java website. In order to place servlets on the internet you will need to have access to a servlet compatible webserver, such as Apache with the JServ module enabled.

Note : The Apache JServ is separate from the main apache distribution, so you will need to obtain both packages.

Important Note :- This tutorial has been written for use with JSDK2.0/2.1 and/or Apache JServ. Both have now been officially superseded by JSDK2.3 and Apache Tomcat respectively. However Tomcat has a number of serious problems which need to be addressed before i'm prepared to recommend it, these are as follows (Warning rant mode=true) :

  • Performance, Tomcat is generally slower than JServ
  • Complexity, Tomcat is considerably more difficult to setup and use.
  • Tomcat can't be easily de-integrated. Tomcat can act as both a servlet engine, JSP engine and a http webserver along with all sorts of other features. From a development point of view this is quite handy, but if your trying to set up a live webserver, you generally want to strip out everything that isn't needed. I suspect this probably can be done, but I can't find anything in the docs which explains how it could be done.
  • Tomcat uses XML Configuration files. Although this is more 'standards compliant', the use of XML in this case has made configuration files longer and more difficult to read. The style used for JServ/Servletrunner is much cleaner and simpler and therefore less prone to error.
  • Related to the above, Tomcat cannot handle JServ configuration files, so for me to switch my own systems would require a lot of work re-writing configuration files.
  • Work on making Tomcat a drop in replacement for JServ has been promised, but I haven't seen anything yet.
  • Tomcat seems to require a special build process using ANT. You can't simply drop class files into a directory and use them.
  • Documentation is poor. I have difficulty understanding the docs and I'm a specialist in Java and Web technologies.

One of these days I may try to set up an open source project to produce a servlet only JSDK 2.2 (or better) api compatible engine with direct JServ compatibility. The aim would be to produce a servlet engine that can communicate with apache using the ajpv21 protocol and reads JServ configuration files. I'm currently investigating two ways of achieving this :

  • Strip down Tomcat to remove the Http + JSP elements and re-write the configuration handling to accept JServ configuration files.
    In theory this will involve less work, however, the poor and confusing nature of the Tomcat docs won't help and the general design of tomcat does not appear to lend itself easily to this kind of work.
  • Use the embeddable element of the Jetty servlet engine with custom written JServ configuration handler and ajpv21 protocol server.
    The configuration handling and http server are both handled by easily identifiable discrete components, which could (in theory) be replaced to make Jetty simulate the behaviour of the JServ. However, the need to implement the ajpv21 protocol could make life difficult. I'm hoping to be able to port across large parts of the code used in JServ

If you know somebody who has already done this (or something similar), please tell me !



Tims Home Page       |       Page last modified : 19 May 2003