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:
- The java program is interpreted by the java interpeter so it
cannot be executed as a single program without arguments.
- 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
-
decodeURL(String)
- Convert an URL-escaped string to a non-escaped string.
-
getBaseURL()
- Returns the Base URL of this script.
-
getCGIEnvironmentVariables()
- Returns a hashtable containing name-value pairs of the cgi environment variables.
-
getFormData()
- Returns a hashtable containing name-value pairs of the data sent via http post,
http put, http get and http isindex.
-
getFullURL()
- Returns the full URL of this script.
-
getInstance()
- Returns a CGI object
-
isGetRequest()
- Returns true if this is a get request
-
isPostRequest()
- Returns true if this is a post request
-
isPutRequest()
- Returns true if this is a put request
-
sendHtml(String)
- Send an html encoded message to the client.
-
sendRedirect(String)
- Sends a url to client to use unstead of current url.
-
sendText(String)
- Send a text message to the client.
getInstance
public static CGI getInstance()
- Returns a CGI object
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.
getCGIEnvironmentVariables
public Properties getCGIEnvironmentVariables()
- Returns a hashtable containing name-value pairs of the cgi environment variables.
The keys are the following strings:
AUTH_TYPE | HTTP_ACCEPT | REMOTE_ADDR | SCRIPT_NAME |
CONTENT_LENGTH | HTTP_USER_AGENT | REMOTE_HOST | SERVER_NAME |
CONTENT_TYPE | PATH_INFO | REMOTE_IDENT | SERVER_PORT |
DOCUMENT_ROOT | PATH_TRANSLATED | REMOTE_USER | SERVER_PROTOCOL |
GATEWAY_INTERFACE | QUERY_STRING | REQUEST_METHOD | SERVER_SOFTWARE |
See NCSA CGI description for details
getBaseURL
public String getBaseURL()
- Returns the Base URL of this script.
getFullURL
public String getFullURL()
- Returns the full URL of this script.
isPostRequest
public boolean isPostRequest()
- Returns true if this is a post request
isGetRequest
public boolean isGetRequest()
- Returns true if this is a get request
isPutRequest
public boolean isPutRequest()
- Returns true if this is a put request
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.
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..
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.
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