All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.net.CGI

java.lang.Object
   |
   +----sdsu.net.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 getFormData() method. Supports data submitted via via http post, http put, http get and http isindex. Don't support all isindex queries. Support queries with path?name=value pairs, but not path?a+b+c

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, Roger Whitney made some modifications to Andrew's code

Method Index

 o decodeURL(String)
Convert an URL-escaped string to a non-escaped string.
 o getBaseURL()
Returns the Base URL of this script.
 o getCGIEnvironmentVariables()
Returns a hashtable containing name-value pairs of the cgi environment variables.
 o getFormData()
Returns a hashtable containing name-value pairs of the data sent via http post, http put, http get and http isindex.
 o getFullURL()
Returns the full URL of this script.
 o getInstance()
Returns a CGI object
 o isGetRequest()
Returns true if this is a get request
 o isPostRequest()
Returns true if this is a post request
 o isPutRequest()
Returns true if this is a put request
 o sendHtml(String)
Send an html encoded message to the client.
 o sendRedirect(String)
Sends a url to client to use unstead of current url.
 o sendText(String)
Send a text message to the client.

Methods

 o getInstance
 public static CGI getInstance()
Returns a CGI object

 o getFormData
 public Properties getFormData()
Returns a hashtable containing name-value pairs of the data sent via http post, http put, http get and http isindex. All name and values are decoded into normal strings. If class is used in an interactive (testing) environment, the hashtable returned will prompt for the value associated a key the first time the key is accessed.

 o getCGIEnvironmentVariables
 public Properties getCGIEnvironmentVariables()
Returns a hashtable containing name-value pairs of the cgi environment variables. The keys are the following strings:
AUTH_TYPEHTTP_ACCEPTREMOTE_ADDRSCRIPT_NAME
CONTENT_LENGTHHTTP_USER_AGENTREMOTE_HOSTSERVER_NAME
CONTENT_TYPEPATH_INFOREMOTE_IDENTSERVER_PORT
DOCUMENT_ROOTPATH_TRANSLATEDREMOTE_USERSERVER_PROTOCOL
GATEWAY_INTERFACEQUERY_STRINGREQUEST_METHODSERVER_SOFTWARE
See NCSA CGI description for details

 o getBaseURL
 public String getBaseURL()
Returns the Base URL of this script.

 o getFullURL
 public String getFullURL()
Returns the full URL of this script.

 o isPostRequest
 public boolean isPostRequest()
Returns true if this is a post request

 o isGetRequest
 public boolean isGetRequest()
Returns true if this is a get request

 o isPutRequest
 public boolean isPutRequest()
Returns true if this is a put request

 o sendText
 public void sendText(String textMessage)
Send a text message to the client. The text will not be rendered as html by client. Useful for sending error messages to client. Can send repeated messages to client.

 o sendHtml
 public void sendHtml(String htmlMessage)
Send an html encoded message to the client. The message will be rendered as html by client. Can send repeated messages to client..

 o sendRedirect
 public static void sendRedirect(String url)
Sends a url to client to use unstead of current url. Url can be a full url or relative to current url. Does not make sense to send another message to client after calling this method, as client will drop connection upon getting this message.

 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

All Packages  Class Hierarchy  This Package  Previous  Next  Index