简体   繁体   English

用Java编写CGI脚本

[英]Writing CGI script in Java

I trying to figure out how to write CGI scripts in Java. 我试图弄清楚如何用Java编写CGI脚本。

I followed this examples -> http://www.javaworld.com/jw-01-1997/jw-01-cgiscripts.html?page=1 我按照这个例子 - > http://www.javaworld.com/jw-01-1997/jw-01-cgiscripts.html?page=1

It provide cgi_lib.java, hello.html and hello.java 它提供了cgi_lib.java,hello.html和hello.java

Everything seems fine, but in the html part. 一切似乎都很好,但在HTML部分。 The action is pointed to cgi_lib/hello.cgi 该操作指向cgi_lib / hello.cgi

There's no cgi provided. 没有提供cgi。 So I tried with cgi_lib/hello.java, and it print the entire source code in the hello.java. 所以我尝试使用cgi_lib / hello.java,它在hello.java中打印完整的源代码。

Then i tried to edit the hello.java extensions into hello.cgi, and tried again. 然后我尝试将hello.java扩展编辑为hello.cgi,然后再次尝试。 The browser returns me error 500. 浏览器返回错误500。

What is the problem? 问题是什么? Is it that, there's some specific method to compile the hello.java into hello.cgi? 是这样的,有一些特定的方法可以将hello.java编译成hello.cgi吗? The script in hello.cgi is different from hello.java? hello.cgi中的脚本与hello.java不同?

Please help. 请帮忙。

Thank you. 谢谢。

UPDATE I added hello.cgi 更新我添加了hello.cgi

#!/bin/sh
java     -Dcgi.content_type=$CONTENT_TYPE     -Dcgi.content_length=$CONTENT_LENGTH     -   Dcgi.request_method=$REQUEST_METHOD     -Dcgi.query_string=$QUERY_STRING     -Dcgi.server_name=$SERVER_NAME     -Dcgi.server_port=$SERVER_PORT     -Dcgi.script_name=$SCRIPT_NAME     -Dcgi.path_info=$PATH_INFO   hello

So is the $CONTENT_TYPE, $CONTENT_LENGTH,... remain the same? 那么$ CONTENT_TYPE,$ CONTENT_LENGTH,......保持不变吗? Or should I enter something? 或者我应该输入什么?

Just to make things clearer. 只是为了让事情更清楚。 I put the the cgi_lib, hello.java and hello.cgi in the C:\\xampp\\cgi-lib 我把cgi_lib,hello.java和hello.cgi放在C:\\ xampp \\ cgi-lib中

And the hello.html in C:\\xampp\\htdocs\\test 和C:\\ xampp \\ htdocs \\ test中的hello.html

When I tried to connect it returns me this 当我尝试连接时,请将此返回给我

Server error!

The server encountered an internal error and was unable to complete your request.

Error message: 
couldn't create child process: 720002: hello.cgi

If you think this is a server error, please contact the webmaster.

Error 500

localhost
Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

I had check the httpd.conf in c:\\xampp\\apache\\conf and configure according to this 我检查了c:\\ xampp \\ apache \\ conf中的httpd.conf并根据配置

LoadModule cgi_module modules/mod_cgi.so ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/" Seems to be already enable. LoadModule cgi_module modules / mod_cgi.so ScriptAlias / cgi-bin /“C:/ Program Files / Apache Group / Apache / cgi-bin /”似乎已经启用。

So whats the problem right now? 那么现在问题是什么?

The contents of hello.cgi is shown at the top of page 2 of the article. hello.cgi的内容显示在本文第2页的顶部。

#!/bin/sh
java     -Dcgi.content_type=$CONTENT_TYPE     -Dcgi.content_length=$CONTENT_LENGTH     -Dcgi.request_method=$REQUEST_METHOD     -Dcgi.query_string=$QUERY_STRING     -Dcgi.server_name=$SERVER_NAME     -Dcgi.server_port=$SERVER_PORT     -Dcgi.script_name=$SCRIPT_NAME     -Dcgi.path_info=$PATH_INFO   hello

The article says that you will execute the java jar from within a cgi script . 文章说你将从cgi脚本中执行java jar。 You need to make sure that this script is set up to execute your jar file by making the correct calls to the java executable with your hello.jar file as the parameter. 您需要确保将此脚本设置为执行jar文件,方法是使用hello.jar文件作为参数正确调用java可执行文件。 Also make sure your web server is configured correctly to allow the execution of cgi scripts. 还要确保正确配置Web服务器以允许执行cgi脚本。

你还必须chmod你的cgi和java文件,以便其他人可以执行它们。

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

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