Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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!

SAMPLE CGI SCRIPT

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

#!/usr/bin/perl

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.

CONFIGURING TOMCAT TO SUPPORT CGI

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:

    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>6</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>
    </servlet>

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

    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>*.cgi</url-pattern>
    </servlet-mapping>

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
  [465] - ()
  [479] - ()
  [754] - ()
  [1006] - ()
  [1074] - ()
  [1082] - ()
  [1192] - ()
  [1552] - ()
  [1564] - ()
  [1909] - ()
  [2088] - ()
  [3044] - ()
  [3996] - ()

Web Application Deployment - Tomcat -Sourcing, Installing and Initial Testing
  [837] - ()
  [1049] - ()
  [1550] - ()
  [2088] - ()
  [3819] - ()

Web and Intranet - Executable Content
  [1812] - ()
  [1813] - ()
  [1814] - ()
  [2628] - ()

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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 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