gpt4 book ai didi

java - 用 Java 编写 CGI 脚本

转载 作者:可可西里 更新时间:2023-11-01 13:36:21 27 4
gpt4 key购买 nike

我想知道如何用 Java 编写 CGI 脚本。

我遵循了这个例子 -> http://www.javaworld.com/jw-01-1997/jw-01-cgiscripts.html?page=1

它提供cgi_lib.java、hello.html和hello.java

一切似乎都很好,但在 html 部分。 Action 指向cgi_lib/hello.cgi

没有提供cgi。所以我尝试使用 cgi_lib/hello.java,它在 hello.java 中打印了整个源代码。

然后我尝试将 hello.java 扩展编辑为 hello.cgi,然后再次尝试。浏览器返回错误 500。

问题是什么?是不是,有什么具体的方法可以把hello.java编译成hello.cgi?hello.cgi 里的脚本跟hello.java 不一样?

请帮忙。

谢谢。

更新我添加了 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... 是否保持不变?或者我应该输入什么?

只是为了让事情更清楚。我把cgi_lib、hello.java 和hello.cgi 放在了C:\xampp\cgi-lib

还有C:\xampp\htdocs\test中的hello.html

当我尝试连接时,它返回给我这个

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 并根据this 配置了

LoadModule cgi_module modules/mod_cgi.soScriptAlias/cgi-bin/"C:/Program Files/Apache Group/Apache/cgi-bin/"好像已经启用了。

那么现在的问题是什么?

最佳答案

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

关于java - 用 Java 编写 CGI 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16223318/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com