jcgi © 1996 Andrew Scherpbier
andrew@sdsu.edu
Please see the file COPYING for license information.
[<path>]<Classname>[.<extension>]to jcgi
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.
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.
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.cgiA 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 = POSTwill appear. (This is assuming that your http server has been set up to accept CGI programs outside of the traditional /cgi-bin tree.)