DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • JMeter Plugin HTTP Simple Table Server (STS) In-Depth
  • Optimizing Database Connectivity: A Comparative Analysis of Tomcat JDBC vs. HikariCP
  • Deployment of Spring MVC App on a Local Tomcat Server
  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC

Trending

  • Java in a Container: Efficient Development and Deployment With Docker
  • Improving Java Application Reliability with Dynatrace AI Engine
  • Manual Investigation: The Hidden Bottleneck in Incident Response
  • Dear Micromanager: Your Distrust Has a Job; It’s Just Not the One You’re Doing
  1. DZone
  2. Coding
  3. Languages
  4. How to Enable CGI Mode in Apache Tomcat

How to Enable CGI Mode in Apache Tomcat

Having trouble enabling the CGI mode in your Apache Tomcat? Check out this tutorial to learn more!

By 
Anil AGRAWAL user avatar
Anil AGRAWAL
·
Jul. 16, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
29.6K Views

Join the DZone community and get the full member experience.

Join For Free

Hello Coders, I hope you are all doing well.

Today, I had to enable the CGI mode in Tomcat, while facing lots of issue in the same. So, I thought that, after successful deployment, I would write an article in the same simplified steps. Here it is!

  • First, download the Apache Tomcat (choose the version that is compatible with your application; in my case, I am using the latest one).
  • Go to the CATALINA_HOME/conf and modify the following files:
    • web.xml (Here, we will enable the CGI support in Tomcat)
      • To enable CGI support in Tomcat, we have to uncomment servlet and servlet-mapping of CGI servlet in web.xml.
      • After uncommenting the servlet and servlet-mapping of CGI, we have to add one param value in that servlet mapping to execute our CGI.
    • context.xml
      • We have to set the attribute "privileged" to true for Context.
<!-- web.xml -->

<servlet>
  <servlet-name>cgi</servlet-name>
  <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
  <init-param>
    <param-name>executable</param-name>
    <param-value></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-mapping>
	<servlet-name>cgi</servlet-name>
	<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>


<!-- context.xml -->

<Context privileged="true">
</Context>


  • Go to the CATALINA_HOME/webapps/ROOT/  directory.
    • Check weather WEB-INF  directory is exist or not, if not create the directory  WEB-INF .
    • Create another directory named as cgi under  WEB-INF.
  • Now, your Tomcat is CGI enabled. You can copy any CGI file under this directory, and it will run successfully.
  • Your base URL will be <<request protocol>>>://<<server-ip>>:<<server-port>>/cgi-bin/<<name of cgi>>, in my case i.e. http://localhost:8080/cgi-bin/test.cgi
  • For more understanding, you can look for CGI-howto section in Tomcat

Let me know if you face any issue after this deployment. Happy Coding!

Apache Tomcat

Opinions expressed by DZone contributors are their own.

Related

  • JMeter Plugin HTTP Simple Table Server (STS) In-Depth
  • Optimizing Database Connectivity: A Comparative Analysis of Tomcat JDBC vs. HikariCP
  • Deployment of Spring MVC App on a Local Tomcat Server
  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook