Servlet Configuration  «Prev  Next»

Lesson 5 The JSDK server
Objective Use the JSDK server.

JSDK Server History

The "let" in the word servlet is to remind you that a servlet is not an application by itself. You can not just run it; it runs within another application, a Web server in this case.
You need a Web server that supports servlets installed on your computer and you already have one if you installed the JSDK. By installing the JSDK, you also installed a tiny little Web server.
The JSDK server is fairly useless as an ordinary Web server. The only requests it can handle are requests for servlets.
It can be used to test your servlets on your own machine. Like all servers, the JSDK server has to be started before you can use it. To start the JSDK server from an MS-DOS prompt, change to the JSDK installation directory (c:\jsdk2.1) and type in the following command:
startserver

This will start the tiny Web server with the default settings, which should be fine for your purposes. (UNIX users also type
startserver
which is the full name of the command in the UNIX JSDK.)
You can specify the directory where the JSDK server looks for servlets by editing the file default.cfg located in the JSDK installation directory. For example, to set this directory to the examples directory that comes with the JSDK, change the server.docbase property to examples. It should look like this:
server.docbase=examples

Java Servlets

The servlets directory is located at
docbase/WEB.INF/servlets
If the JSDK server clashes with another server already installed on your system, you can change the server.port property in the default.cfg file as well.
Once the JSDK server is started, open a Web browser. In the address field, enter the URL,
          
http://localhost:8080/servlet/SimpleServlet
.
The following MouseOver explains the URL and shows how it looks in a browser.

Java Simple Servlet
  1. localhost is a special keyword identifying your own computer. 8080 is the port that JSDK server uses. (Most Web browsers try port 80 by default, so in this URL we tell the browser what port to use.)
  2. /servlet/SimpleServlet is the path to one of the sample servlets that comes with the JSDK.
  3. The servlet output appears as HTML in the browser.

Simple Servlet JSDK
From the JSDK installation directory (c:\jsdk2.1) you can stop the JSDK server by typing the following command:
stopserver

JSDK Server - Exercise

JSDK Server - Exercise
In the next lesson, you will learn about the Java Web Server.