[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Writing CGI in Java

Posted on 1999-01-05
2
Medium Priority
?
252 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

656 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