项目中要用tomcat调用cgi,在网上找了一些资料都是用tomcat5.5配置,因为tomcat6和tomcat5有很大的改变,所以配置并不使用。只能自行研究,结果如下:
tomcat6已经把servlets-cgi.jar集成到catalina.jar,无需象tomcat5.5一样配置jar包;
1、去掉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>passShellEnvironment</param-name>
<param-value>true</param-value>//?
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi-bin</param-value>//此处映射真实路径
形式为tomcat path+projectname+param-value
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>cmd /c</param-value> //c++的cgi解析方式
</init-param>
<init-param>
<param-name>clientInputTimeout</param-name>
<param-value>100</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>
2、配置权限
在conf/context
<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>
不配置步骤2,将会出现java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application这一异常。