在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!");