The web server for the incredibly lazy...

jhttpd is an Java HTTP web server with a number of unusual features.

  • Source level compatable with servlet 2.1 container.
  • It is has only 50k of source which is freely available.
  • It recompiles classes automatically when source changes.
  • It can pre-empt a servlet when a user cancels the load of a page.
  • It can run signed inside Internet Explorer as an applet.
  • It has a Java version of the popular Perl module CGI.pm
  • It will run Perl CGI scripts and "Perl Server Pages"

    Using these features it is possible to quickly develop web applications under UNIX using the incremental compile feature as you would a scripting language. These applications can then be deployed to a conventional web server or as an applet web application served by its own web server running inside the client such as www.dbexplorer.com or inside a Java host app for example www.dbeclipse.org.

    To use jhttpd download the full distribution here to extract the following:

    jhttpd/jhttpd.sh  # runs the server
    jhttpd/jhttpd.bat # runs the server (your mileage may vary)
    jhttpd/lib        # jar files to include in classpath
    jhttpd/docs       # root for documents served by server
    jhttpd/src        # place for java servlet source
    
    Use jhttpd.sh to start the server and browse to the web address given (port 8089). The default page (index.html) has pointers to example servlet (JGI), CGI and Perl server pages (PGI) as starting points. Servlets are contained in the "src" directory and have the class name as the first component of the URL's path.
  •  

    Advanced Features

    The web server requires a full Java jdk (a.k.a SE) to be installed from java.sun.com and for the environment variable JAVA_HOME to be set to the place where this is installed. Once this is set up you can devlope the server itself incrementally by unziping the contents of lib/jhttpd.jar to place it's source in the "src" directory and then removing the file lib/jhttpd.jar. The web server will then recompile itself each time a request is served apart from a small set of bootstrap and ClassLoader code in org/jhttpd/WebServer.java.

    The server can also be used from inside a web page itself using a Java applet. The advantage of this is that the ease of development of web applications can be realised while serving requests from the client itself removing the requirement for a server.

    To write an embedded web application such as this the jhttpd.jar needs to be signed and a pair of frames used, one to host the applet while pages are served in the other. To use the applet use the following HTML markup:

    <applet name='WebServer' code='org/jhttpd/WebServer.class'
      width=0 height=0 codebase='jars' archive='jhttpd.jar,app.jar'
      onload='appletLoaded( "{0}", {1} );'
      onerror='appletFailed( "{0}" );' mayscript>
      <param name='port' value='18089'>
    </applet>
    
    Application servelet code is placed in the file app.jar on the web site and documents & images are also contained in this file under a "docs" directory. When the applet has loaded, function appletLoaded( host, port ) is called to load the first page into the other frame and switch to it. If you don't believe this is possible see how www.dbexplorer.com uses this to implement a db browser client inside Internet Explorer. This application is developed under UNIX then deployed as applet jars for use in over the Internet/Intranet.

    Enjoy using jhttpd - we do. If you have any comments or suggestions for enhancements you can send them to us at

    If you have used jhttpd and have found it usefull you can support the author by donating through paypal by clicking here: