jcgi: wrapper program to execute java CGI programs

jcgi © 1996 Andrew Scherpbier andrew@sdsu.edu
Please see the file COPYING for license information.


Synopsis

Symbolic link of the form
[<path>]<Classname>[.<extension>]
to jcgi

Description

This program can be used to overcome two problems with Java as a CGI programming language:
  1. CGI parameters are passed through the environment. Java programs do not have access to the environment.
  2. CGI programs need to be a standalone command. Java programs have to be run using the java interpeter. (i.e.: java <Classname>)
The environment variable problem is solved by passing the appropriate variables on the java command line using the "-Dname=value" method.

The second problem is solved by having the jcgi program execute the java interpreter with the appropriate class name. The class name and location are extracted from argv[0] of the jcgi program. To use jcgi with a Java program, all you need to do is to create a symbolic link (or hard link, it doesn't matter) from jcgi to a file that is the name of the class you want to execute. There can also be an optional extension on the link (like ".cgi") in case your HTTP server wants that.

The Java program itself will have to parse the CGI variables. A class which will do this is sdsu.CGI.

Configuration

The only configuration that needs to be performed is possibly changing the definition of the JAVA from "/opt/java/bin/java" to wherever your java interpreter resides.

CGI Variables

The following is a list of environment variables which will be available in the java program when jcgi is used:

In addition to these, any environment variable that starts with "HTTP_" will also be passed.

The java program can access these variables with the System.getProperty(<variablename>) call.

Example

Given the following Java program in the file 'tester.java':
class tester
{
    public static void main(String a[])
    {
        System.out.println("Content-type: text/plain");
        System.out.println("");
        System.out.println("REQUEST_METHOD = " +
                                System.getProperty("REQUEST_METHOD"));
    }
}
      
and the compiled jcgi in /usr/local/bin, we create a symbolic link:
ln -s /usr/local/bin/jcgi tester.cgi
A minimal HTML file:
<form action="tester.cgi" method="post">
<input type="submit">
</form>
      
If the HTML file is loaded in a browser and the button pressed
REQUEST_METHOD = POST
will appear. (This is assuming that your http server has been set up to accept CGI programs outside of the traditional /cgi-bin tree.)

Files

/opt/java/bin/java
The java interpreter.

See Also

sdsu.CGI java class

Andrew Scherpbier <andrew@sdsu.edu>
Last modified: Tue Mar 19 09:31:33 PST 1996