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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

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

  • Understanding k-NN Search in Elasticsearch
  • Testing Java Applications With WireMock and Spring Boot
  • 12 Principles for Better Software Engineering
  • Advanced gRPC in Microservices: Hard-Won Insights and Best Practices
  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
28.8K 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.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: