簡體   English   中英

如何通過 CGI 腳本運行 jar 文件

[英]How to run jar file through CGI script

我在名為helo.jar的 cgi-bin 文件夾中有一個可執行的 jar 文件和一個hello.sh

這是我的腳本

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

我試圖通過這個 url “ http://localhost/cgi-bin/hello.sh ”運行這個腳本

出現內部服務器錯誤,並檢查日志並顯示“腳本 output 在標頭前結束”

我正在使用可以執行 java 命令的 docker wordpress 容器,而且我是 cgi 程序的新手。

這是我的 Java 代碼

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());
}

我確定我的錯誤在我的腳本中,因為我已經嘗試過其他腳本並且它有效,例如 perl

要使腳本在所有機器上工作,它必須用UNIX編寫,這可能是問題所在。

要解決,您可以:

-如果你有記事本+,go到設置,首選項,新建文檔並切換到UNIX;

- 如果你有一個虛擬機,你可以簡單地做:echo something > name.sh;

你有沒有在你的 java 代碼中嘗試過這個?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM