简体   繁体   English

如何通过 CGI 脚本运行 jar 文件

[英]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我在名为helo.jar的 cgi-bin 文件夹中有一个可执行的 jar 文件和一个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 "我试图通过这个 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"出现内部服务器错误,并检查日志并显示“脚本 output 在标头前结束”

Im working with docker wordpress container that can execute java commands, and I'm new with cgi programs.我正在使用可以执行 java 命令的 docker wordpress 容器,而且我是 cgi 程序的新手。

This is my Java code这是我的 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());
}

I'm sure my error is in my script since I already tried other scripts and it worked, with perl for example我确定我的错误在我的脚本中,因为我已经尝试过其他脚本并且它有效,例如 perl

To make the script work on all machines it must be written in UNIX , this may be the problem.要使脚本在所有机器上工作,它必须用UNIX编写,这可能是问题所在。

To resolve you can:要解决,您可以:

-If you have Notepad +, go to Settings, Preferences, New Document and switch to UNIX; -如果你有记事本+,go到设置,首选项,新建文档并切换到UNIX;

-If you have a virtual machine you can simply do: echo something > name.sh; - 如果你有一个虚拟机,你可以简单地做:echo something > name.sh;

Did you ever try this in your java code?你有没有在你的 java 代码中尝试过这个?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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