简体   繁体   中英

How to run jar file through CGI script

I have a executable jar file in the cgi-bin folder called helo.jar and a hello.sh

this is my script

#!/bin/bash 
java -jar helo.jar

I tried to run this script through this url " http://localhost/cgi-bin/hello.sh "

Got an Internal Server Error, and checked the logs and it said "End of script output before headers"

Im working with docker wordpress container that can execute java commands, and I'm new with cgi programs.

This is my Java code

public static void main( String args[] )
 {
  //  Here is a minimalistic CGI program that uses cgi_lib
  //  Print the required CGI header.
  System.out.println(cgi_lib.Header());

  //  Parse the form data into a Hashtable.
  Hashtable form_data = cgi_lib.ReadParse(System.in);

  // Create the Top of the returned HTML page
  System.out.println("Here are the name/value pairs from the form:");

  //  Print the name/value pairs sent from the browser.
  System.out.println(cgi_lib.Variables(form_data));

  System.out.println("Nome: " + form_data.get("name"));
  System.out.println("<p>");
  System.out.println("Email: " + form_data.get("email"));      
  System.out.println("<p>");

  System.out.println(cgi_lib.HtmlBot());
}

I'm sure my error is in my script since I already tried other scripts and it worked, with perl for example

To make the script work on all machines it must be written in UNIX , this may be the problem.

To resolve you can:

-If you have Notepad +, go to Settings, Preferences, New Document and switch to UNIX;

-If you have a virtual machine you can simply do: echo something > name.sh;

Did you ever try this in your java code?

#!/usr/bin/java --source 11

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM