1、修改conf/web.xml
找到并将cgi的servlet和servlet-mapping的注释去掉
注意:其中cgiPathPrefix是cgi文件的存放路径,默认是WEB-INF/cgi,我为了方面用awstats,所以改成cgi-bin
/cgi-bin/*意思是,访问cgi文件的默认地址为cgi-bin/*
2、修改conf/context.xml
<!-- 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>
修改<Context>添加privileged="true"属性,否则页面提示Servlet CGI is not availabled,且tomcat会有错误提示java.lang.SecurityException: Restricted classclass org.apache.catalina.servlets.CGIServlet
3、如果tomcat的版本是6以下的,必须将server/lib/目录下的servlets-cgi.renametojar改名为servlets-cgi.jar
有以上三步,已经可以成功配置CGI了,访问地址如http://localhost:8080/cgi-bin/test.pl