Link to home
Start Free TrialLog in
Avatar of petrow
petrow

asked on

Writing CGI in Java

I decided to try to write a Java CGI program as an experiment to see how well it ports from UNIX to Win9*
(yes, I know it's slow as a dog and wouldn't work well
in practice...)

The Java source code is:
import java.lang.*;

public class JavaHello {
  public static void main(String argv[]) {
    char space = ' ', newline = '\n', plus = '+';
    String request = System.getProperty("JavaHello.request");
    String clength = System.getProperty("JavaHello.clength");
    String query_s = System.getProperty("JavaHello.query");
    StringBuffer query = new StringBuffer(query_s);
    for (int i=0;i<query.length();i++) {
      if (query.charAt(i) == plus) {
        query.setCharAt(i,space);;
      }
    }
    query_s = query.toString();
    System.out.println("Content-type: text/plain");
    System.out.println();
    System.out.println("Hello World!");
    System.out.println("Request type is " + request);
    System.out.println("Query String is " + query_s);
    System.out.println("Content-Legnth: " + clength);
    System.out.flush();
  }
}

This is called by a shell script javahello.cgi in UNIX:
#!/bin/sh
JAVA_HOME=/usr/local/jdk1.1.3
PATH=/usr/local/jdk1.1.3/bin:/usr/local/jdk1.1.3/bin:/usr/local/bin:/bin:/usr/bin:.:/usr/X11R6/bin:/usr/bin/mh:/usr/X11R6/bin:/usr/bin/mh
cd /home/httpd/html/JAVAtest/joetest
-DJavaHello.query=$QUERY_STRING -DJavaHello.clength=$CONTENT_LENGTH JavaHello
exec java -DJavaHello.request=$REQUEST_METHOD -DJavaHello.query=$QUERY_STRING -DJavaHello.clength=$CONTENT_LENGTH JavaHello
#java JavaHello

My question is, how would I get this to run on a Windows
server?

ASKER CERTIFIED SOLUTION
Avatar of yoren
yoren

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yoren
yoren

Somehow my answer got a bit jumbled -- your batch file will work better if you don't include my name in it. Instead, include the stuff below it.