Tomcat cgi(exe类型的)问题

kkkwdb 2009-06-07 12:54:07
在Tomcat中执行CGI(exe类型的)程序时出现了问题,我大概的配置是:

系统:winxp sp3
server: Tomcat6.0
Tomcat 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>cmd /c</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>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>

context.xml片断
<Context privileged="true">

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->

<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
</Context>

目录,cgi文件:
D:\Program Files\apache-tomcat-6.0.18\webapps\
myweb\WEB-INF\cgi\cgi_test.exe #自己建的

cgi_test.exe源代码:
#include<stdio.h>
void main(){
FILE* file=fopen("aaa.txt","w");
fprintf(file,"hellow");
fclose(file);
fprintf(stdout,"content-type:text/html");
fprintf(stdout,"hellow world!");
}

结果:
Firefox中输入 http://localhost:8080/myweb/cgi-bin/cgi_test.exe
显示下载cgi_test.exe,创建aaa.txt文件.
问题:
1 我本想在网页上输出hellow world,但却显示下载,为什么?
2 创建了aaa.txt文件,说明cgi_test.exe执行了,但网页没有显示内容,我认为是标准输出没有正确定向。是吗,
哪的问题呢?
哪位高手指教一下,不胜感激.
...全文
301 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyre129 2009-06-30
  • 打赏
  • 举报
回复
学习了。
tfxg 2009-06-09
  • 打赏
  • 举报
回复
content-type:text/html後面要加個空行的
kkkwdb 2009-06-08
  • 打赏
  • 举报
回复
没人明白吗,俺自己解决了
cgi_test.exe源代码改为:
#include <stdio.h>
void main(){
FILE* file=fopen("aaa.txt","w");
fprintf(file,"hellow");
fclose(file);
fprintf(stdout,"content-type:text/html\n\n");
fprintf(stdout,"hellow world!");
}
就OK了

2,204

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧