Fundamentals of JavaTM Servlets: Magercises
Help: Hosting with servletrunner

By MageLang Institute

[Help | Solution | API Docs | Expected Output | Course Notes | Magercises | Module Intro]

Help is available for each task, or you can go straight to the solution source code.

Task 1

Compile the HelloWorldServlet.java file using your favorite Java compiler.

If you are using the JDK, go to the directory with the HelloWorldServlet.java file and compile with:

  javac HelloWorldServlet.java

Task 2

Run servletrunner to host your servlet.

With the JSDK 2.0, you will find servletrunner in the \bin directory and the supporting JAR file, jsdk.jar in the \lib directory. You must first check to see that your PATH and CLASSPATH environment variable include these directories.

For example, with JSDK 2.0 installed within the default Windows target directory your PATH environment variable should include C:\jsdk2.0\bin and the CLASSPATH environment variable should include C:\jsdk2.0\lib\jsdk.jar

To run servletrunner, it is best to use a batch file. You must enter the absolute path to the directory containing your servlets. Since this could be a long path, a skeleton batch file, runit.bat, has been included with the solution. Edit this file so that the -d parameter points to the directory containing the servlet class files.

The execute the batch file from the command prompt:

runit

If this is run successfully, you will see the following on your screen:

servletrunner starting with settings:
  port = 8088
  backlog = 50
  max handlers = 100
  timeout = 5000
  servlet dir = <points to your servlet directory>
  document dir = .
  servlet propfile = 
    <points to your servlet directory>\servlet.properties

This is indicating that servlet hosting server is now available on the machine localhost on port 8088.

Task 3

Activate the servlet from your browser by clicking here or by typing the URL
  http://localhost:8088/servlet/HelloWorldServlet

into your browser.

Copyright © 1998 MageLang Institute. All Rights Reserved.