?
Solved

Writing CGI in Java

Posted on 1999-01-05
2
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
yoren earned 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

741 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