To enable Tomcat's CGI servlet, you must do the following:
1.Rename the file servlets-cgi.renametojar (found in CATALINA_HOME/server/lib/) to servlets-cgi.jar, so that the servlet that processes CGI scripts will be on Tomcat's CLASSPATH.
2. In Tomcat's web.xml file, uncomment the definition of the servlet named cgi (this is around line 235 in the distribution).
3. Also in Tomcat's web.xml, uncomment the servlet mapping for the cgi servlet (around line 290 in the distributed file). Remember, this specifies the HTML links to the CGI script.
Either place the CGI scripts under the WEB-INF/cgi directory (remember that WEB-INF is a safe place to hide things that you don't want the user to be able to view for security reasons), or place them in some other directory within your context and adjust the cgiPathPrefix parameter to identify the directory containing the files. This specifies the actual location of the CGI scripts, which typically will not be the same as the URL in the previous step.
Restart Tomcat, and your CGI processing should now be operational.