Let Tomcat start EXE in CGI Path

How to activate CGI in Tomcat

[a] uncomment in conf/web.xml the bloc <servlet-name>cgi</servlet-name>
[b] uncomment the bloc of servlet mapping for cgi (begins with <servlet-mapping>)

[Before Tomcat 6.0]
[c] in /server/lib rename the file servlets-cgi.renametojar with servlets-cgi.jar

Create the folders "webappsmycgiWEB-INFcgi" and create there a new file called time.cgi with the following code:


print "Content-type: text/htmlnn";

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

Start Tomcat. The call http://localhost:8080/mycgi/cgi-bin/time.cgi should give something like It is Thu Nov 5 13:54:18 2009


By default, Tomcat is configured to consider the files with the .cgi extension as Perl scripts. If you want to start an exe file, the solution is to configure the file conf/web.xml with the following parameter at the place of your CGI configuration


Warning ! That gives yet the rights an Tomcat to start any type of file. So, be careful and specify the language (Ruby, Objective-C for example) in the param-value.

1 Poster un commentaire

Inscrivez-vous au blog

Soyez prévenu par email des prochaines mises à jour