[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Using UP.SDK with Web Servers and CGI Scripts
Section 24 out of 26 total sections , Section 4 out of 5 sections in this chapter


Creating and testing CGI programs

The sdk_installdir/examples directory includes sample CGI utilities and applications implemented in both C and Perl.

The Perl code below is a simple CGI script that generates the HDML deck described in the previous section. A line-by-line description follows the code.

1    #!/usr/local/bin/perl5.001
2   
3    push (@INC, "../apputils");
4    require 'HDMLUtils.pl';
5   
6    #$AppUtils::CGIStandard;
7   
8    $DECK =
9        "<HDML VERSION=3.0>
10            <DISPLAY>
11                Hello Unwired World!
12            </DISPLAY>
13        </HDML>";
14   
15    #Output the deck
16    &AppUtils::OutputDeck($DECK);

Line 1

This line identifies the Perl version to use. Change this line as needed for your server. Note that if you are calling UP.SDK Perl utilities (as this program does), you must use Perl 5.001 or higher.


Lines 3-4

These lines include the HDMLUtils.pl utility file provided in the UP.SDK. This file defines the OutputDeck() function, which the application uses to output HDML. Note that the push statement assumes that the UP.SDK Perl utilities are in the apputils directory, within the current directory's parent directory. Be sure to modify this for your own directory structure.


Lines 8-13

These lines define the HDML deck--the same deck used in Testing a static HDML deck on your Web server.


Line 16

This line uses the OutputDeck() utility function to send the deck as an HTTP response. The OutputDeck() function outputs the HDML and adds the HTTP header to it. It has the same result as the following lines of code:

The OutputDeck() function assumes that your Web server follows Netscape conventions and automatically adds the HTTP/1.0 status line to the HTTP response header. If your Web server does not follow Netscape conventions, uncomment line 6 by removing the hashmark (#). This sets a flag that instructs the OutputDeck() function to include the status line.

For a complete description of the OutputDeck() and other sample Perl utilities, see the UP.SDK Tools and APIs Reference.



Testing the CGI program

To test the CGI program with the UP.Simulator, follow these steps.

  1. Save the CGI program with the appropriate filename extension.
  2. It is recommended that you use a .cgi extension. Make sure that your Web server maps the .cgi extension to a Perl 5 interpreter. Also make sure you have set the program's file permissions so that it is executable.

  3. Put the program in your Web server's document tree.
  4. To make the program accessible to the UP.Simulator, you must put it in a directory that is served by your Web server.

  5. Start the UP.Simulator.
  6. The procedure for starting the UP.Simulator is described in Using the UP.Simulator.

  7. In the Go field below the UP.Simulator menu bar, type the URL of the CGI script you created and press Enter.
  8. The UP.Simulator displays the card shown in Figure 3-5. The only difference is the URL in the Go field.


[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Using UP.SDK with Web Servers and CGI Scripts
Section 24 out of 26 total sections , Section 4 out of 5 sections in this chapter


Copyright © 1999, Unwired Planet, Inc. All rights reserved.