Class sdsu.CGI
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.CGI

java.lang.Object
   |
   +----sdsu.CGI

public class CGI
extends Object
This class is an interface to the Common Gateway Interface protocol used by most Unix based HTTP servers. It will take the values of an HTML form and make them available to the program through the get() method.

By itself, a java program cannot be used as a CGI program for two reasons:

  1. The java program is interpreted by the java interpeter so it cannot be executed as a single program without arguments.
  2. The CGI protocol uses environment variables to pass parameters from the HTTP server to the CGI program. Java doesn't have access to the environment variables.
For this reason, a companion program, jcgi, needs to be used.

The parsing of the CGI protocol stuff is done by the constructor of this class.

If this class is used in an interactive (testing) environment, requests for values will cause a interactive prompts. Once the value has been entered once, it is not asked for again. This is useful for debugging purposes.

Author:
Andrew Scherpbier

Constructor Index

 o CGI()
This constructor will parse the CGI protocol information.

Method Index

 o decodeURL(String)
Convert an URL-escaped string to a non-escaped string.
 o displayError(String)
Simple routine which can be used to display an error message.
 o get(String)
Request a specific value.
 o names()
Enumerate all the names of the CGI form values.

Constructors

 o CGI
  public CGI()
This constructor will parse the CGI protocol information.

Methods

 o get
  public String get(String name)
Request a specific value. If this is used interactively, the first time a value is requested it is prompted for.
Parameters:
name - the name of the value to get
Returns:
the value or null if there was no such value.
 o names
  public Enumeration names()
Enumerate all the names of the CGI form values. The elements are Strings.
 o decodeURL
  public String decodeURL(String URL)
Convert an URL-escaped string to a non-escaped string. The special characters this method knows about are '+' which is converted to a space, and '%' which is followed by two hex digits that make up the character. The reverse action or converting a string into an URL-escaped string can be accomplished using the java.net.URLEncoder.encode() method.
Parameters:
URL - the escaped string
Returns:
the non-escaped string
 o displayError
  public void displayError(String message)
Simple routine which can be used to display an error message. It is aware of the HTTP protocol so the first time it is called in a non-interactive mode, it will output the correct HTTP headers.
Parameters:
message - the message to display

All Packages  Class Hierarchy  This Package  Previous  Next  Index