【问题标题】:How to run jar file through CGI script如何通过 CGI 脚本运行 jar 文件
【发布时间】:2020-09-30 12:59:15
【问题描述】:

我在 cgi-bin 文件夹中有一个名为 helo.jar 的可执行 jar 文件和一个 hello.sh

这是我的脚本

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

我试图通过这个网址“http://localhost/cgi-bin/hello.sh”运行这个脚本

遇到内部服务器错误,并检查日志并显示“在标头之前结束脚本输出”

我正在使用可以执行 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

【问题讨论】:

    标签: bash sh cgi executable-jar cgi-bin


    【解决方案1】:

    你有没有在你的 java 代码中尝试过这个?

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

    【讨论】:

      【解决方案2】:

      要使脚本在所有机器上运行,它必须用 UNIX 编写,这可能是问题所在。

      要解决,您可以:

      -如果你有记事本+,转到设置、首选项、新建文档并切换到UNIX;

      -如果你有虚拟机,你可以简单地做:echo something > name.sh;

      【讨论】:

        猜你喜欢
        • 2011-07-16
        • 2011-11-14
        • 1970-01-01
        • 2016-07-22
        • 1970-01-01
        • 2012-05-31
        • 1970-01-01
        • 2012-02-16
        相关资源
        最近更新 更多