|
Open SiteSearch 4.1.1 Final |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ORG.oclc.ecat.util.cgi_lib
cgi_lib.java
Usage: This library of java functions, which I have encapsulated inside a class called cgi_lib as class (static) member functions, attempts to duplicate the standard PERL CGI library (cgi-lib.pl). You must invoke any Java program that uses this library from within a UNIX script, Windows batch file or equivalent. As you will see in the following example, all of the CGI environment variables must be passed from the script into the Java application using the -D option of the Java interpreter. This example UNIX script uses the "main" routine of this class as a CGI script:
(testcgi.sh) #!/bin/sh java \ -Dcgi.content_type=$CONTENT_TYPE \ -Dcgi.content_length=$CONTENT_LENGTH \ -Dcgi.request_method=$REQUEST_METHOD \ -Dcgi.query_string=$QUERY_STRING \ -Dcgi.server_name=$SERVER_NAME \ -Dcgi.server_port=$SERVER_PORT \ -Dcgi.script_name=$SCRIPT_NAME \ -Dcgi.path_info=$PATH_INFO \ cgi_libQuestion and comments can be sent to pldurante@tasc.com.
Constructor Summary | |
cgi_lib()
|
Method Summary | |
static String |
Environment()
Neatly format all of the CGI environment variables and the associated values using HTML. |
static String |
Header()
Generate a standard HTTP HTML header. |
static String |
include(String file)
Load the contents of a file into a string. |
static void |
main(String[] args)
The main routine is included here as a test CGI script to demonstrate the use of all of the methods provided above. |
static boolean |
MethGet()
Determine if the REQUEST_METHOD used to send the data from the browser was the GET method. |
static boolean |
MethPost()
Determine if the REQUEST_METHOD used to send the data from the browser was the POST method. |
static String |
MyBaseURL()
Determine the Base URL of this script. |
static String |
MyFullURL()
Determine the Full URL of this script. |
static String |
printHead(String Title)
Generate some vanilla HTML that you usually want to include at the top of any HTML page you generate. |
static String |
printTail()
Generate some vanilla HTML that you usually want to include at the bottom of any HTML page you generate. |
static Hashtable |
ReadParse(InputStream inStream)
Parse the form data passed from the browser into a Hashtable. |
static String |
urlDecode(String in)
URL decode a string. Data passed through the CGI API is URL encoded by the browser. |
static String |
Variables(Hashtable form_data)
Neatly format all of the form data using HTML. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public cgi_lib()
Method Detail |
public static Hashtable ReadParse(InputStream inStream)
<INPUT SIZE=40 TYPE="text" NAME="email" VALUE="pldurante@tasc.com">then after calling this method like this,
Hashtable form_data = cgi_lib.ReadParse(System.in);you can access that email field as follows:
String email_addr = (String)form_data.get("email");
inStream
- The input stream from which the form data can be read.
(Only used if the form data was posted using the POST method. Usually,
you will want to simply pass in System.in for this parameter.)public static String urlDecode(String in)
Data passed through the CGI API is URL encoded by the browser. All spaces are turned into plus characters (+) and all "special" characters are hex escaped into a %dd format (where dd is the hex ASCII value that represents the original character). You probably won't ever need to call this routine directly; it is used by the ReadParse method to decode the form data.
in
- The string you wish to decode.public static String Header()
public static String printHead(String Title)
Title
- The title you want to put on the page.public static String printTail()
public static boolean MethGet()
public static boolean MethPost()
public static String MyBaseURL()
public static String MyFullURL()
public static String Environment()
public static String Variables(Hashtable form_data)
form_data
- The Hashtable containing the form data which was
parsed using the ReadParse method.public static String include(String file)
file
- The file to be loaded.public static void main(String[] args)
Please note that this routine references the member functions directly (since they are in the same class), but you would have to reference the member functions using the class name prefix to use them in your own CGI application:
System.out.println(cgi_lib.printHead());
args
- An array of Strings containing any command line
parameters supplied when this program in invoked. Any
command line parameters supplied are ignored by this routine.
|
Open SiteSearch 4.1.1 Final |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |