首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CGI >

Tomcat cgi(exe类型的)有关问题

2012-12-14 
Tomcat cgi(exe类型的)问题在Tomcat中执行CGI(exe类型的)程序时出现了问题,我大概的配置是:系统:winxp sp3

Tomcat cgi(exe类型的)问题
在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执行了,但网页没有显示内容,我认为是标准输出没有正确定向。是吗,
  哪的问题呢?
哪位高手指教一下,不胜感激.
[最优解释]
content-type:text/html後面要加個空行的
[其他解释]
没人明白吗,俺自己解决了
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了 
[其他解释]
学习了。
[其他解释]
该回复于2009-11-05 09:20:24被版主删除

热点排行