Chapter 1: Introduction to CGI-based Applications

You need to do the tutorials in this book in the order shown by the Tutorials Map.

Overview of CGI

The tutorials in your Getting Started book describe component-based technologies that can be used for distributed applications, including Web applications. This part of this Getting Started - Additional Topics book describes an older technology for Web applications.

A server-side program is a program that is loaded by a Web server, generally in response to a request from a Web browser, and runs on the Web server machine. Typically the request has been generated because the program was named in a Web form loaded in the browser, and its purpose is to process data the user has entered in that form.

There are several protocols that a program can conform to in order that it can be loaded by a Web server. The oldest established of these is the Common Gateway Interface (CGI) protocol. The program runs as a separate process. It can be in any language - it could be for example, a shell script, or a C program, or a COBOL program - in fact anything that could be called from the command line. Provided it conforms to CGI, it is compatible with any Web server.

Alternative protocols to CGI are Internet Server Application Programming Interface (ISAPI) and Netscape Server Application Programming Interface (NSAPI). With a development environment such as Net Express, changing a program from CGI to ISAPI or NSAPI is simply a matter of setting different options and rebuilding. Consequently this choice is not a fundamental decision, and you can if you wish use CGI during development and then switch to ISAPI or NSAPI for production. Colloquially, the term CGI program or just CGI is often used for any server-side program. We will follow this practice in the rest of this part of this book.

Writing a CGI program is normally a fairly complex task, but Net Express generates them for you. The CGIs that Net Express creates are in COBOL.

CGI in Net Express

In Net Express, you can create a CGI Web application in three ways:

For all three cases you use the Internet Application Wizard. In the first case you first use HTML Page Wizard and Form Designer to design the form yourself. After that, the three ways of using Internet Application Wizard are very similar, in that you give it the one existing item - form, program, or database - and it generates the rest of the application for you.

Forms and form-handling code generated in this way are based on standard templates supplied with Net Express. You can edit the forms and form-handling code later if you want to customize them to your own exact requirements.

The sessions in this Part take you through these three ways of using Internet Application Wizard. You can use any Web browser to test your applications in these sessions.

Solo

You can use any Web server software to test your applications. In these sessions we use Solo, the Web server software included in Net Express. It is designed especially for testing CGI-based applications developed using Net Express. It is not designed for use as a production Web server. Solo needs no configuration or setup. (If you want to see how it is automatically configured, see the appendix Configuring Your Web Server.)

Server-side Programs

In a server-side program created using Net Express, the input/output of the form is done by two Micro Focus extensions to COBOL: an extended ACCEPT statement, and an EXEC HTML statement (known as Embedded HTML) which outputs HTML written within the statement. The form has to include a "Submit" button; when the end-user clicks this, the program runs on the Web server. The ACCEPT statement inputs data from the form.

Micro Focus COBOL also has an extended DISPLAY statement, but the EXEC HTML statement is more powerful.

Structure

A server-side program typically consists of little more than:

  1. The ACCEPT statement to input the data from the input form.
  2. Code to move the data from the data items associated with the input form to your work areas.
  3. The business logic you've inserted.
  4. Code to move the results from your work areas to the data items associated with the form.
  5. The EXEC HTML statement(s) to create the output form(s).

Notice that:

Symmetric and Asymmetric

An application can use the same form for both input and output, or use separate forms.

In Net Express, an application with only one form is called symmetric. Typically, it is started by the end-user running the executable. You'd probably create a Web page with a link to the executable. When the end-user clicks this, the program runs once, displaying the form on the browser. The end-user fills in the form, clicks the Submit button, and the program runs again to process the data and display the results. The form is then ready for the end-user to use again.

An application with separate input and output forms is called asymmetric. Typically, it is started by the end-user loading the input form. You'd probably create a Web page with a link to this form. When the end-user clicks this, the form is loaded. The end-user fills in the form, clicks the Submit button, and the program runs to process the data and display the output form with the results. To enter the next query, the end-user loads the input form again. (Though if the output form contains all the input fields that the input form does, the user can get away with using it for input rather than bothering to reload the input form - the program won't know the difference, as it knows only that it's receiving data from a browser.)

If an application uses more than one input form, you create a separate server-side program for each one.

Next...

Start at the next chapter, Creating a Web Application.


Copyright © 2006 Micro Focus (IP) Ltd. All rights reserved.