|The servletrunner that's supplied with the JSDK is a useful utility for testing and debugging Java servlets before you deploy them to your web server. This article answers basic questions about the servletrunner, and provides a step-by-step description of how to test a simple "Hello, world" Java servlet using the servletrunner.|
Once you've developed a servlet with JBuilder, Visual Cafe, the Java JDK, or other development tools, you'll want to test the servlet. You can test it by plugging it right into your servlet-compatible web server, or you can take another approach -- testing it first with the servletrunner that comes with the Java Servlet Development Kit (JSDK).
In this article, we'll show you how to test simple Java servlets with
Five questions about the servletrunner
1. What's a servletrunner?
Here's what the JSDK 2.0 documentation says about the servletrunner:
|The servletrunner is a small utility, intended for testing.
It is multithreaded, so it can run more than one servlet. It can be used, therefore, to run multiple servlets simultaneously, or to test one servlet that calls other servlets in order to satisfy client requests. Unlike some web servers, it does not automatically reload servlets when they are updated. Because it is small, however, there is very little overhead associated with stopping and restarting it in order to use a new version of a servlet.
(re-printed from the JSDK 2.0 documentation.)
Note that if you have a more complicated Java servlet that requires
the passing of parameters to the servlet, you'll have a few more steps
to follow before starting the servletrunner.
REM PURPOSE: Run the JSDK 'servletrunner'
REM JDK installed in C:\JAVA\JDK1.1.5
REM JSDK installed in C:\JAVA\JSDK2.0
bin\servletrunner -d .
|Listing 1:||This is the DOS batch file that I use to start the servletrunner. Because I use several different IDE's, I use this file to overwrite my PATH and CLASSPATH variables before starting the servletrunner.|
As a next level of support, the servletrunner also includes
a useful -help switch that briefly lists the command-line
options. Here's what it looks like when you invoke it in a DOS window:
Usage: servletrunner [options]
-p port the port number to listen on
-b backlog the listen backlog
-m max maximum number of connection handlers
-t timeout connection timeout in milliseconds
-d dir servlet directory
-r root document root directory
-s filename servlet property file name
-v verbose output
To see the default values of these options, start the servletrunner
with the -v switch. This has the side effect of starting the servletrunner,
but it's easy to stop. Here's some sample output:
port = 8080
backlog = 50
max handlers = 100
timeout = 5000
servlet dir = .\examples
document dir = .\examples
servlet propfile = .\examples\servlet.properties
In a related servlet article, we showed you how to create a simple "Hello, world" servlet using JBuilder 2. Let's quickly walk through the steps that are required to test that Java servlet in the servletrunner.
The servletrunner that's supplied with the JSDK is a useful utility for testing and debugging Java servlets before you deploy them to your web server. This article answers basic questions about the servletrunner, and provides a step-by-step description of how to test a simple "Hello, world" servlet. In a future article, we'll discuss the additional steps that may be required to test your more complicated Java servlets.