[英]Why do I get a blank page when using Python CGI in Tomcat
I just began to learn Python CGI, but I did not make it even to testing the simplest Python CGI program.我刚开始学习 Python CGI,但我什至没有完成测试最简单的 Python CGI 程序。
I use Tomcat 6.0.我使用 Tomcat 6.0。 I have already deleted the comments in
web.xml
and also added <Context privileged="true">
.我已经删除了
web.xml
中的评论,还添加了<Context privileged="true">
。 In web.xml
, I gave the "cgiPathPrefix" the value "cgi-bin", and I added this cgi-bin
folder in the webapps/ROOT
directory.在
web.xml
中,我将“cgiPathPrefix”的值设置为“cgi-bin”,并在webapps/ROOT
目录中添加了这个cgi-bin
文件夹。
The cgi program is simple; cgi程序很简单; as follows with the name
test.cgi
:名称如下
test.cgi
:
#!/usr/bin/python
print("Content-type: text/html")
print()
print("<title>CGI 101</title>")
print("<h1>A First CGI Example</h1>")
print("<P>Hello, CGI World!</p>")
When I go to http://localhost:8080/cgi-bin/test.cgi
, I just get a blank page.当我 go 到
http://localhost:8080/cgi-bin/test.cgi
时,我只是得到一个空白页。
What's wrong with this setup?这个设置有什么问题?
I had the same problem in a different context.我在不同的上下文中遇到了同样的问题。 Basically, I think the OP's issue was solved in the comments to the question, by eryksun, with the suggestion:
基本上,我认为 eryksun 在对问题的评论中解决了 OP 的问题,并提出了以下建议:
Is the executable parameter set to an empty string?可执行参数是否设置为空字符串?
Using Tomcat 7.0 I had everything set up so that the server did not produce any errors on startup, and it allowed me to request from the WEB-INF/cgi with a 200 "OK" response, but it gave a blank html page, just like the OP noted.使用 Tomcat 7.0 我设置了所有内容,以便服务器在启动时不会产生任何错误,它允许我从 WEB-INF/cgi 请求一个 200“OK”响应,但它给出了一个空白的 html 页面,只是就像OP指出的那样。
The solution was to extend the default parameters to the conf/web.xml:解决方案是将默认参数扩展到 conf/web.xml:
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
**<init-param>
<param-name>executable</param-name>
<param-value>c:\myexact\path\to\perl.exe</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment </param-name>
<param-value>true</param-value>
</init-param>**
<load-on-startup>5</load-on-startup>
</servlet>
My additions are bolded (**) above.我的补充在上面加粗(**)。
Basically the critical info comes from the source suggested by eryksun:基本上,关键信息来自 eryksun 建议的来源:
http://tomcat.apache.org/tomcat-7.0-doc/cgi-howto.html http://tomcat.apache.org/tomcat-7.0-doc/cgi-howto.html
Your sample code is not proper HTML.您的示例代码不正确 HTML。 You need at least
你至少需要
<html>,<head> and <body>
tags.标签。
If adding those does not heal the problem then it is a problem with your server configuration and probably the question is more suitable to serverfault.com how to debug what's wrong with your Tomcat.如果添加这些不能解决问题,那么这是您的服务器配置的问题,并且问题可能更适合 serverfault.com 如何调试您的 Tomcat 出了什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.