用Java编写CGI脚本 [英] Writing CGI script in Java
问题描述
我试图弄清楚如何用Java编写CGI脚本。
I trying to figure out how to write CGI scripts in Java.
我遵循了以下示例-> http://www.javaworld.com/jw-01-1997/jw-01-cgiscripts.html? page = 1
I followed this examples -> http://www.javaworld.com/jw-01-1997/jw-01-cgiscripts.html?page=1
它提供cgi_lib.java,hello.html和hello.java
It provide cgi_lib.java, hello.html and hello.java
一切似乎都很好,但是在html部分。
该操作指向cgi_lib / hello.cgi
Everything seems fine, but in the html part. The action is pointed to cgi_lib/hello.cgi
没有提供cgi。因此,我尝试使用cgi_lib / hello.java,它在hello.java中打印了整个源代码。
There's no cgi provided. So I tried with cgi_lib/hello.java, and it print the entire source code in the hello.java.
然后,我尝试将hello.java扩展名编辑为hello。 .cgi,然后重试。
浏览器向我返回错误500。
Then i tried to edit the hello.java extensions into hello.cgi, and tried again. The browser returns me error 500.
出了什么问题?
是不是有某种特定的方法将hello.java编译为hello.cgi?
hello.cgi中的脚本与hello.java不同吗?
What is the problem? Is it that, there's some specific method to compile the hello.java into hello.cgi? The script in hello.cgi is different from hello.java?
请帮助。
谢谢。
UPDATE
我添加了hello.cgi
UPDATE I added 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
那么$ CONTENT_TYPE,$ CONTENT_LENGTH,...保持不变吗?还是我应该输入一些东西?
So is the $CONTENT_TYPE, $CONTENT_LENGTH,... remain the same? Or should I enter something?
只是为了使事情更清楚。
我将cgi_lib,hello.java和hello.cgi放入C:\xampp\cgi-lib
Just to make things clearer. I put the the cgi_lib, hello.java and hello.cgi in the C:\xampp\cgi-lib
然后将hello.html放入C:\xampp\htdocs\test
And the hello.html in C:\xampp\htdocs\test
当我尝试连接它时,我会返回
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
我在c:\xampp\apache\conf中检查了httpd.conf并根据此
I had check the httpd.conf in c:\xampp\apache\conf and configure according to this
LoadModule cgi_module modules / mod_cgi。因此
ScriptAlias / cgi-bin / C:/ Program Files / Apache Group / Apache / cgi-bin /
似乎已经启用。
LoadModule cgi_module modules/mod_cgi.so ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/" Seems to be already enable.
那么现在出了什么问题?
So whats the problem right now?
推荐答案
hello.cgi的内容显示在第2页的顶部
The contents of hello.cgi is shown at the top of page 2 of the article.
#!/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
这篇关于用Java编写CGI脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!