Utilizing Java in a CGI environment
February 9th, 2008
Today, I began to wonder if it was possible to use Java in a CGI environment. I then realized, of course you can. Nearly anything is possible via CGI when using a shell script wrapper. I wrote a simple cgi script which executes a java class java-test.cgi:
[noland@a90 cgi-bin]$ cat java-test.cgi #!/bin/sh /usr/java/java1.5/bin/java CgiJavaTest
Here is the source of the CgiJavaTest class:
[noland@a90 cgi-bin]$ cat CgiJavaTest.java
public class CgiJavaTest {
public static void main(String[] args) {
System.out.println("Content-Type: text/plain; charset=UTF-8\n");
System.out.println("It worked!");
}
}
Of course, creating a JVM is pretty expensive….


February 10th, 2008 at 1:14 am
Utilizing Java in a CGI environment can show wonder.
February 10th, 2008 at 1:33 pm
Ain’t tomcat cheaper?
February 12th, 2008 at 12:54 am
Check out servlets and servlet containers like websphere / apache tomcat / jboss - it’s like this but with big brass ones…
February 12th, 2008 at 1:34 am
@Roman
Much so. You’d have to really want to use some java class here and not be able to use tomcat before you’d do this. I was just showing its possible.