Home:ALL Converter>Run CGI Java Program

Run CGI Java Program

Ask Time:2017-01-12T00:23:12         Author:Teodor Dimitrov

Json Formatter

I want to run a java program with Apache HTTP Server. I'm struggling to show simple output in the browser.

In my cgi-bin folder I have CgiTest.java which looks like this:

#!"C:\Program Files\Java\jdk1.8.0_101\bin\java.exe"
public class CgiTest {
public static void main(String[] args) {
    String type = "Content-Type: text/html\n\n";
    String output = "<html>" +
            "<p>Hi there </p>" +
            "</html>";
    System.out.println(type);
    System.out.println(output);
}
}

The error I get is:

End of script output before headers: CgiTest.java
Error: Could not find or load main class C:.Apache24.cgi-bin.CgiTest.java\r: C:/Apache24/cgi-bin/CgiTest.java

How to run my java program? If I have to invoke it from some script how to do it?

Author:Teodor Dimitrov,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/41595828/run-cgi-java-program
yy