CGI
Home ] Up ] HTTP ] A Simple Java Web Server ] [ CGI ] Java Servlets ] Apache Tomcat ] Tomcat Directory Structure ] Creating a Web Application ] Web Application Directory Structure ] What's a Servlet? ] Generating Other Content ] The Servlet Life Cycle ] Servlets & Form Data ] Request Headers ] CGI Variables ] Redirection ]

 

 

The problem with plain HTML pages is that they are static, and never change.

If we want to do something more dynamic -- for example, show the details of a book which the user specifies -- then we have to do something to cause HTML pages to be generated dynamically.

The Common Gateway Interface (CGI) was the first solution to this problem.  A Web server that implements CGI recognizes that certain requested resources are special, and redirects the request to a separate program for processing.  The program may be written in just about any language: C, C++, Perl, Java, etc. and is dynamically launched by the web server as a result of receiving the request.

The CGI request is typically handled like this:

  1. The Web server receives a request for a resource (for example: /cgi-bin/foo)
  2. The Web server recognizes that the resource either is in a "special folder" cgi-bin, or that it has a .cgi filetype, and so knows that it should launch the specified file foo as a program.  The Web server passes to the CGI program a set of "CGI variables" in the form of environment variables, and other items in the form of command line arguments.  The CGI program's stdin is supplied by the web server, and its stdout and stderr go to the web server.
  3. The foo program executes, processing the necessary information based on the command line arguments and environment variables, and generates a dynamic HTML document, which it outputs to its stdout.
  4. The Web server receives the output from the CGI program, and returns it to the client.

Note that, to the client, this process is transparent. The client is not aware that a CGI program was involved.

So, every time you go to a Web search engine and type in something to search for, the search engine is doing something like this to generate its results dynamically.

 

The page was last updated February 19, 2008