CSc31800 Internet Programming

Spring 2004, CCNY-CUNY, Jinzhong Niu

Project #3 - Web Server (due info)

Updated on 04/01/2004

The goal of this project is to develop a web server, which can concurrently respond to web clients by returning the requested resource if everything goes smoothly or notifying the occurence of errors. You are strongly recommended to do so in Java, though C/C++ may also be used.


  1. Your program is supposed to work in the following way:

  2. Suppose the main class of your program is WebServer.class. Then the following command should execute your web server and log is supposed to be outputted showing which document is requested and how the request is responded.
    $ cd <directory holding your classes>
    $ java WebServer

    Your server is supposed to run on any Window machine in T513 and be able to respond to any web browser on the same machine or its neighbors. Due to technical difficulties that the administrators cannot or are unwilling to handle, we will not use the Solaris platform in UNIX lab to demonstrate your web server.

  3. A plain text config file should be used for customizing the execution of the server. By editing the file, different port number, document root, or other arguments may be speciifed for the server.

  5. Your server should be capable of not only providing static documents already available under the document root upon request from clients but also executing CGI programs to process information submitted by users through HTML FORMs. The directory containing those CGI programs should also be configurable in the config file.

    Due to security and platform-independence concerns, Java cannot set and read environment variables in the same way like other programming languages. To get around this limit (if it is), a Java CGI API (a Java package called org.ccny.cgi) has been defined in  javacgi.jar. You should implement such an API in your web server and code your Java CGI programs according to the specification so that the server can run them. 

    The Java CGI API includes:
    1. org.ccny.cgi.Program, defining a framework for Java CGI programs;
    2. org.ccny.cgi.Request, defining the input interface for Java CGI programs, HTTP FORM request only;
    3. org.ccny.cgi.Response, defining the output interface for Java CGI programs;
    4. Other interfaces or classes, playing less important roles.

    To have Java CGI programs work on your web server, you should at least define two implementing classes, one for org.ccny.cgi.Request and the other for org.ccny.cgi.Response, so that the instances of both classes can contain information to/from CGI programs so that they can be used as parameters for org.ccny.cgi.Program's run() method. org.ccny.cgi.Example is a sample Java CGI program, where you may have a sense of what a Java CGI program looks like.

    Same as traditional CGI programs, Java CGI programs (in the form of Java classes) should be put in the web server's directory for CGI programs, like .../cgi-bin/. But instead of launching a process in the traditional way, your web server should first load the classes (refer to JDK docs about java.lang.ClassLoader) and then use Java Reflection mechanism (java.lang.reflect) to create an instance of the Java CGI program class before invoking its run() method.

  6. Basic HTTP authentication mechanism should be supported by your server. The access control should be configurable in the config file, though the format is up to you. More specifically, web masters of your web server can define a directory under the document root and all resources in it as a realm, for which a basic-authentication-based protection policy may be defined.

  8. Persistent connection is recommended to be supported but not required.

  10. A NBA all-star vote website can be deployed on your server. The features of such a website is up to you.

  12. You need to write a report 2+ pages long describing your design and how your program works step by step, i.e. how an HTTP connection is setup, how a request is received and how the response is generated and sent to the client.

Since this project turns out to be much bigger than what I originally expected, we divide the project into several stages, each associated with a due date:

  1. can serve static files, supports basic authentication.

  2. due on Mon - 03/15
  3. supports CGI, thus can generate dynamic pages, and works as a NBA all-star vote website.

  4. due on Wed - 04/28
At the end of each stage, you are supposed to submit a printed coy of both the latest version of your report and your program.


  1. You need to use Java multi-threading mechanism to enable multiple clients to be served simultaneously.
  2. Whenever you need more information about something, say base64, always remember to use google. By skillfully choosing key words, you will usually get what you want.

© Jinzhong Niu, 2004