Solved

Writing CGI in Java

Posted on 1999-01-05
2
220 Views
Last Modified: 2013-12-25
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?

0
Comment
Question by:petrow
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
yoren earned 100 total points
ID: 1830488
Basically, it's the same, except environment variables are accessed a bit differently.

1. Set up Java. If you're running Windows 95 or 98, define CLASSPATH and PATH in Autoexec.bat. If you're running NT, define them in Control Panel - System - Environment.

2. Do nothing to your Java program.

3.Convert your shell script to a .BAT file, as follows (all on 1 line):

Yuval

java -classpath "%CLASSPATH%;c:/my/program/is/here"
-DJavaHello.query=%QUERY_STRING% -DJavaHello.clength=%CONTENT_LENGTH% -DJavaHello.request=%REQUEST_METHOD%  -DJavaHello.query=%QUERY_STRING%
 -DJavaHello.clength=%CONTENT_LENGTH% JavaHello

0
 
LVL 7

Expert Comment

by:yoren
ID: 1830489
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now