Home

JSP and Beyond

a pragmatic primer on building web-based solutions with Java technologies


Common Gateway Interface (CGI)

CGI is not a programming language, but a standard way for a web server to communicate with other applications running on a server. CGI was developed by the National Center for Supercomputing Applications in 1993.

You might therefore ask why this is included in the Dynamic Web History section. CGI was the first major method by which dynamic web content was generated and is still serving dynamic content on the web for many sites today. Most CGI programs are written in Perl and there are a wide range of web sites that provide Perl scripts for guest books, shopping carts and other web application components.

That being said, there are a few drawbacks that make other development options more attractive for building web-based applications.

CGI Hello World
# Hello world in perl
print “Hello World!\n”;

Drawbacks of CGI
There is nothing inherently wrong with using this tool to build applications, but CGI does suffer from some general problems

Scalability - Each time a request is made to a CGI application the application needs to be instantiated, respond to the request and then be destroyed. This is a very high overhead operation for each request and is a major drawback of CGI technology

Security - CGI applications are generally run under accounts with permission to access files and OS related operations. A poorly written CGI program can inadvertently open security holes in an application.

Runtime - Any errors that occur through a CGI application have the ability to harm the operation of the web server, since it is closely tied to the OS.

Debugging - Debugging a CGI application can be more difficult than in other languages used for the web (ASP, PHP, ASP.NET and JSP).

Limited Functionality - More modern languages designed for the web have access to more information about the environment, whereas CGI is restricted to the elements from a form post or get.

Separation of Presentation and Logic – In CGI code, both presentation and business logic are mixed. That means that anyone who is developing a CGI application will have to retain specialists in the language used to develop their application in order to make any changes to the appearance. It also means that a CGI page can contain a large amount of code that is difficult to maintain.