----
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>";
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>
<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>
<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
No comments:
Post a Comment