UP.SDK Getting Started Guide

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

Current chapter: Chapter 4 - Using 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 WML 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 'DeckUtils.pl';
5   
6    #$AppUtils::CGIStandard;
7   
8    $DECK =
9    "<wml>
10        <card>
11         <p>
12            Hello, Unwired World!
13         </p>
14        </card>
15    </wml>";
16   
17    #Output the deck
18    &AppUtils::OutputDeck($DECK);

Line 1

This line identifies the Perl version to use. Change this line as needed for your server. You must use Perl 5.001 or higher to call the UP.SDK Perl utilities.


Lines 3-4

These lines include the DeckUtils.pl utility file provided in the UP.SDK. This file defines the OutputDeck() function, which the application uses to output WML. 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-15

These lines define the WML deck--the same deck used in Testing a Static WML Deck.


Line 18

This line uses the OutputDeck() function to send the deck as an HTTP response. This function outputs the WML and adds XML and HTTP headers. It has the same result as the following lines of Perl code:

printf('Content-type: text/vnd.wap.wml');  
printf("\n");  
printf("\n");  
printf('<?xml version="1.0"?>');  
printf("\n");  
printf('<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD wml 1.0//EN"');  
printf('"http://www.wapforum.org/DTD/wml_1.1.xml">');  
printf("\n");  
printf($DECK);  

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

For a complete description of 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 served by your Web server.

  5. Start the UP.Simulator (see Starting the UP.Simulator).
  6. Type the URL of your CGI script in the Go field and press Enter (on your computer keyboard).

The UP.Simulator displays the card shown in Figure 3-4. The only difference is the URL in the Go field.


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


Part Number DKGS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.