JHttpServer is very simple pure Java HTTP server implementing javax.servlet interfaces. It was designed to be used with JRacer WebDAV server and other examples of Web application. It can not be used as normal HTTP server, because it can not access file itself and the only things it do - manage pool of session threads and redirects requests to servlets.

JHttpServer is optimized to provide the best performance for client application. It supports persistent connections and doesn't break the connection until client will do it itself. Each connection is handled by own thread. When number of active connections exceeds limit for maximal number of threads, JHttpServer delay accepting of new connections and waits until one of the active sessions is terminated and it's thread can be used for new connection.

Installation and building

All JHttpServer classes are placed in httpserver.jar archive which is included in distribution. Also the distribution contains servlet.jar package with javax.servlet.* interfaces, jaas.jar which can be used to use JAAS with JDK1.3.

If you want to perform build of httpserver.jar yourself, then use compile.bat or build.xml files. First one is DOS batch file which performs compilation of source using javac compiler. Another one is project file for ANT building tool. If you have ANT installed and be available through the PATH environment variable, then just execution of ant will build the project.

Server startup

To run JHttpServer, you need to include httpserver.jar in classpath. All parameters to the server are passed though the command line using system properties and list of arguments consisting of <servlet-path servlet-class> pairs. Currently JHttpServer recognize the following properties:

Property nameProperty descriptionDefault value
portPort at which server will listen for clients connections8080
lingerSocket linger time10
maxThreadsMaximal number of threads which server can spawn64
debugJRacer will dump received queries and send repliesfalse
authTypeAuthentication type (anonymous, everyone, jaas)anonymous
configConfiguration file with
sessionTimeoutTimeout in milliseconds for waiting request by the server after which session will be closed and thread returned in thread pool0 (disabled)
ssl-supportEnables SSL connectionsfalse
ssl-portPort used by SSL443
ssl-authenticateAccept or reject unauthenicated usersfalse
ssl-cert-fileFile generated by keytoolkeystore
ssl-cert-passwordCertificate passowrd-

Properties can be also specified in "" file. Servlet configuration properties are taken either from file "", or, if this file doesn't exists, from JHttpServer properties.

Example of running JHttpServer:

    java -Dport=80 -DmaxThreads=100 org.garret.httpserver.JHttpServer /webdav webdav.WebdavServlet

Using secure sockets

JDav is able to establish secure connections with client thorugh secure sockets (SSL). To it you need first to generate sertificate. It can be done with keytool:

Create a new keystore and self-signed certificate with corresponding public/private keys. 
% keytool -genkey -alias duke -keyalg RSA \
  -validity 7 -keystore keystore 

 Enter keystore password:  password
 What is your first and last name?
 [Unknown]:  Duke
 What is the name of your organizational unit?
 [Unknown]:  Java Software
 What is the name of your organization?
 [Unknown]:  Sun Microsystems, Inc.
 What is the name of your City or Locality?
 [Unknown]:  Palo Alto
 What is the name of your State or Province?
 [Unknown]:  CA
 What is the two-letter country code for this unit?
 [Unknown]:  US 
 Is CN=Duke, OU=Java Software, O="Sun Microsystems, Inc.",
 L=Palo Alto, ST=CA, C=US correct?
 [no]:  yes

 Enter key password for 
  (RETURN if same as keystore password):  
This is the keystore that the server will use. 
To enable SSL connections you should specify the following properties to JHttpServer:

-Dssl-support=trueEnables SSL connections
-Dssl-port=PORTPort used by SSL (by default 443)
-Dssl-authenticate=BOOLEANBy default SSL accept unauthenicated users
-Dssl-cert-file=FILEFile generated by keytool
-Dssl-cert-password=PASSWORDCertificate password

Server commands

When JHttpServer is started, it outputs the prompt and accepts the following commands:

Command nameCommand description
helpoutput list of accepted commands
infooutput some information about the current server state
exitshutdown the server


Directory "tst" contains SimpleServlet example. This servlet allows you to browse your local file system from internet browser. Compile this example using compile.bat file and run it StartServer.bat script. If will start JHttpServer on your computer using port 80. If this port is used, please specify alternative port in StartServer.bat. Then in your browser specify url of your computer - for example http://localhost. You will see content of the content of root directory (if you have permissions to list it).