Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
Running CGI scripts in Apache Tomcat

CGI scripts are usually run under an httpd web server, but if you've only got a few CGIs and a lot of .jsp-s and servlets, you may want to run them under Tomcat instead. It can be done, but there are some configuration things to do first!


Here's a sample cgi script that you might want to install on your Tomcat server:


print "Content-type: text/html\n\n";

$now = localtime();
print "<h1>It is $now</h1>";

The file should be:
 * In a directory called WEB-INF/cgi in the webapp
 * have an extension .cgi
 * be set to be executable (chmod a+x xxxxxx)

If you want to vary the location and extension, you can do so by altering the text configuration quoted below.


Although CGI support is shipped with the standard Tomcat load, the vital information that you'll need is commented out in the web.xml file and you need to uncomment the following to add in the support:


and also you need to map appropriate URLs on to that support:


There's one further change to make - the CGI API is provided in a .jar file that you need to rename in the /usr/local/tomcat/server/lib (or similarly named) directory:

mv servlets-cgi.renametojar servlets-cgi.jar

See also Deploying applications under httpd and Tomcat

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Web Application Deployment - Tomcat - Configuring Web Applications
  [3996] Tips on Tomcat - moving applications around - (2013-02-05)
  [3044] Changing a Servlet - more that just editing and compiling - (2010-11-12)
  [2088] Changing the 404 - file not found - page in Tomcat - (2009-03-18)
  [1909] javax.servlet cannot be resolved - how to solve - (2008-11-26)
  [1564] Default file (MiMe types) for Apache httpd and Apache Tomcat - (2008-03-04)
  [1552] Extra public classes in deploying Apache httpd and Tomcat - (2008-02-24)
  [1192] What are WEB-INF and META-INF directories? - (2007-05-18)
  [1082] Straight from the .jar - (2007-02-16)
  [1074] Java beans and classes, .war and .jar files - (2007-02-10)
  [1006] Apache httpd and Apache Tomcat together tips - (2006-12-24)
  [754] tar, jar, war, ear, sar files - (2006-06-10)
  [479] New servlet from old - (2005-10-28)
  [465] Changing Tomcat's web.xml and reloading a web application - (2005-10-15)

Web Application Deployment - Tomcat -Sourcing, Installing and Initial Testing
  [3819] Packing a tar, jar or war file - best practise - (2012-07-26)
  [2088] Changing the 404 - file not found - page in Tomcat - (2009-03-18)
  [1550] Java (JSP and Servlet examples) live on our server - (2008-02-23)
  [1049] Java 6, Apache Tomcat 6. - (2007-01-21)
  [837] Tomcat - Shutdown port - (2006-08-18)

Web and Intranet - Executable Content
  [2628] An example of an injection attack using Javascript - (2010-02-08)
  [1814] Javascript/HTML example, dynamic server monitor - (2008-09-28)
  [1813] Ajax - going Asyncronous and what it means - (2008-09-28)
  [1812] Starting Ajax - easy example of browser calling up server data - (2008-09-27)

resource index - Java
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/java-run ... omcat.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard