Java Reference
In-Depth Information
This web server requires only two configuration arguments. Both of these are specified
in the command line. The two parameters are:
• HTTP Port
• HTTP Root Directory
For example, to start the web server using port 8080 and the directory
c:\httproot\ as the root directory, the following command is used.
WebServer 8080 c:\httproot\
The above command simply shows the abstract format to call this recipe, with the appro-
priate parameters. For exact information on how to run this recipe refer to Appendix B, C, or
D, depending on the operating system you are using. The web server featured in this recipe
is an expanded version of the server featured in Recipe 1.1. Because of this the details will not
be repeated that are the same between the two web servers; therefore, Recipe 1.1 should be
reviewed for additional information.
Now the construction of the web server will be examined. Listing 1.7 shows the source
code necessary for the file based web server.
Listing 1.7: File Based Web Server (WebServer.java)
package com.heatonresearch.httprecipes.ch1.recipe2;
import java.io.*;
import java.net.*;
import java.util.*;
public class WebServer
{
/*
* The server socket.
*/
private ServerSocket serverSocket;
/*
* The directory to contain HTML and image files.
*/
private String httproot;
/**
* Construct the web server to listen on the specified
* port.
*
* @param port The port to use for the server.
* @param httproot The root directory for HTML and image files.
* @throws IOException Thrown if any sort of error occurs.
*/
Search WWH ::




Custom Search