Enabling CGI in Tomcat

text zoom

Enabling CGI in Tomcat

The CGI (Common Gateway Interface) defines a way for a web server to interact with external content-generating programs, which are often referred to as CGI programs or CGI scripts. Mostly the CGI scripts are used to fetch the data from the content servers and render in form of web pages using some content servers. By default CGI support is disabled in tomcat. The following are the steps for enabling the CGI support in tomcat.

1.Remove the XML comments from around the CGI servlet and servlet-mapping configuration in conf/web.xml. The code is as follows:-














2. Set the privileged="true" for the <context> which will be using the CGI. The code is as follows:-

<Context privileged="true" docBase="JSPExample" path="/JSPExample" reloadable="true" source="org.eclipse.jst.j2ee.server:JSPExample"/>


Note:- There are several servlet init parameters which can be used to configure the behaviour of the CGI servlet.

  • cgiPathPrefix - The CGI search path will start at the web application root directory + File.separator + this prefix. The default cgiPathPrefix is WEB-INF/cgi

  • debug - Debugging detail level for messages logged by this servlet. Default 0.

  • executable - The of the executable to be used to run the script. Default is perl.

  • parameterEncoding - Name of the parameter encoding to be used with the GCI servlet. Default is System.getProperty("file.encoding","UTF-8").

  • passShellEnvironment - Should the shell environment variables (if any) be passed to the CGI script? Default is false.


Copyright © 2015 VisualBuilder. All rights reserved