ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaie_5.4.0.1/rzag3ch1cgiprocess.htm

650 lines
38 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="topic" />
<meta name="DC.Title" content="The CGI Process" />
<meta name="abstract" content="Usually CGI programs are referred to from within HTML documents. In general, the HTML document format defines the environment variables that specify the passing of information. When you design the layout of your HTML document, you must keep in mind how a CGI program might affect the look of your document. Developing the CGI program along with the HTML document will help you avoid many design mistakes." />
<meta name="description" content="Usually CGI programs are referred to from within HTML documents. In general, the HTML document format defines the environment variables that specify the passing of information. When you design the layout of your HTML document, you must keep in mind how a CGI program might affect the look of your document. Developing the CGI program along with the HTML document will help you avoid many design mistakes." />
<meta name="DC.Relation" scheme="URI" content="rzaieparcgi.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2002,2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2002,2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzag3ch1cgiprocess" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>The CGI Process</title>
</head>
<body id="rzag3ch1cgiprocess"><a name="rzag3ch1cgiprocess"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">The CGI Process</h1>
<div><p>Usually CGI programs are referred to from within HTML documents.
In general, the HTML document format defines the environment variables that
specify the passing of information. When you design the layout of your HTML
document, you must keep in mind how a CGI program might affect the look of
your document. Developing the CGI program along with the HTML document will
help you avoid many design mistakes.</p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzaieparcgi.htm" title="This topic provides information about Common Gateway Interfaces (CGI).">Common Gateway Interface</a></div>
</div>
</div><div class="nested1" xml:lang="en-us" id="overview"><a name="overview"><!-- --></a><h2 class="topictitle2">Overview</h2>
<div><p>The CGI process involves three players: The web browser, the web server,
and the CGI program. To exemplify how CGI programs for online forms work,
let us assume that the web browser has already requested and obtained an HTML
form.</p>
<ol><li>The user clicks buttons or enters information in fields, and then clicks
on an HTML button to submit the request.</li>
<li>The web browser then sends the data to the web server in an encoded format.
For example, the data might consist of responses on an HTML form.</li>
<li>When the web server receives data, it converts the data to a format compliant
with the CGI specification for input and sends it to the CGI program.</li>
<li>The CGI program then decodes and processes the data.</li>
<li>The system sends this response back to the web server in a form that is
compliant with the CGI specification for output.</li>
<li>The web server then interprets the response and forwards it to the web
browser.</li>
</ol>
<div class="note"><span class="notetitle">Note:</span> If a CGI application program must change HTTP Server job attributes
while processing, the CGI program must restore the attributes to their initial
values before the CGI program ends. Failure to restore job attributes that
are changed in the CGI program will result in unpredictable responses to future
server requests. For example, a CGI program that requires a library in the
library list needs to add the library to the library list. The CGI program <strong>must</strong> remove
the library list before the CGI program ends.</div>
<p>The following HTML form illustrates the various types of fields:</p>
<div class="note"><span class="notetitle">Note:</span> The CGIXMP.EXE program referred to in this sample is just an example;
it is not shipped with the server product.</div>
<pre>&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;CGIXMP Test Case&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;H1&gt;CGI Sample Test Case&lt;/H1&gt;
Fill in the following fields and press APPLY.
The values you enter will
be read by the CGIXMP.EXE program and displayed in a simple HTML
form which is generated dynamically by the program.
&lt;P&gt; &lt;HR&gt;
&lt;form method=POST action="/cgi-bin/cgixmp"&gt;
&lt;P&gt;
&lt;H3&gt;Checkbox Field&lt;/H3&gt;
&lt;P&gt;
&lt;PRE&gt;
&lt;input type="checkbox" name="var1" value="123"&gt;
Check to set variable VAR1 to 123&lt;BR&gt;
&lt;input type="checkbox" name="var2" value="XyZ" checked&gt;
Check to set variable VAR2 to XyZ&lt;BR&gt;
&lt;/PRE&gt;
&lt;P&gt;
&lt;H3&gt;Radio Button Field&lt;/H3&gt;
&lt;P&gt;
&lt;PRE&gt;
&lt;input type="radio" name="var3" value="1"&gt;
Select to set variable VAR3 to 1&lt;BR&gt;
&lt;input type="radio" name="var3" value="2"&gt;
Select to set variable VAR3 to 2&lt;BR&gt;
&lt;input type="radio" name="var3" value="3" checked&gt;
Select to set variable VAR3 to 3&lt;BR&gt;
&lt;input type="radio" name="var3" value="4"&gt;
Select to set variable VAR3 to 4&lt;BR&gt;
&lt;/PRE&gt;
&lt;P&gt;
&lt;H3&gt;Single selection List Field&lt;/H3&gt;
&lt;P&gt;
&lt;PRE&gt;
Select a value for variable VAR4 &lt;select size=1 name="var4"&gt;
&lt;option&gt;0&lt;option&gt;1&lt;option&gt;2&lt;option&gt;3
&lt;option&gt;4&lt;option&gt;5&lt;/select&gt;
&lt;/PRE&gt;
&lt;P&gt;
&lt;H3&gt;Text Entry Field&lt;/H3&gt;
&lt;P&gt;
&lt;PRE&gt;
Enter value for variable VAR5 &lt;input type="text" name="var5"
size=20 maxlength=256 value="TEST value"&gt;
&lt;/PRE&gt;
&lt;P&gt;
&lt;H3&gt;Multiple selection List Field&lt;/H3&gt;
&lt;P&gt;
&lt;PRE&gt;
Select a value for variable VAR6
&lt;select multiple size=2 name="var6"&gt;
&lt;option&gt;Ford&lt;option&gt;Chevrolet&lt;option&gt;Chrysler&lt;option&gt;
Ferrari&lt;option&gt;Porsche
&lt;/select&gt;
&lt;/PRE&gt;
&lt;P&gt;
&lt;H3&gt;Password Field&lt;/H3&gt;
&lt;P&gt;
&lt;PRE&gt;
Enter Password
&lt;input type="password" name="pword" size=10 maxlength=10&gt;
&lt;/PRE&gt;
&lt;P&gt;
&lt;H3&gt;Hidden Field&lt;/H3&gt;
&lt;P&gt;
&lt;input type="hidden" name="hidden" value="Text not shown on form..."&gt;
&lt;P&gt;
&lt;PRE&gt;
&lt;input type="submit" name="pushbutton" value="Apply"&gt;
&lt;input type="reset" name="pushbutton" value="Reset"&gt;
&lt;HR&gt;
&lt;/PRE&gt;
&lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;</pre>
</div>
</div>
<div class="nested1" xml:lang="en-us" id="sendinginformationtotheserver"><a name="sendinginformationtotheserver"><!-- --></a><h2 class="topictitle2">Sending Information to the Server</h2>
<div><p>When you fill out a form, the web browser sends the request to the server
in a format that is described as <dfn class="term">URL-encoded</dfn>. The web browser
also performs this function whenever you enter a phrase in a search field
and click on the submission button. In URL-encoded information:</p>
<ul><li>The URL starts with the URL of the processing program.</li>
<li>A question mark (?) precedes attached data, such as name=value information
from a form, which the system appends to the URL.</li>
<li>A plus sign (+) represents spaces.</li>
<li>A percent sign (%) that is followed by the American National Standard
Code for Information Interchange (ASCII) hexadecimal equivalent of the symbol
represents special characters, such as a period (.) or slash (/).</li>
<li>An ampersand (&amp;) separates fields and sends multiple values for a
field such as check boxes.</li>
</ul>
<div class="note"><span class="notetitle">Note:</span> The method attribute specifies how the server sends the form information
to the program. You use the GET and POST methods in the HTML file to process
forms. The <dfn class="term">GET</dfn> method sends the information through environment
variables. You will see the information in the URL after the ″?″ character.
The <dfn class="term">POST</dfn> method passes the data through standard input. <p>The
main advantage of using the GET method is that you can access the CGI program
with a query without using a form. In other words, you can create canned queries
that pass parameters to the program. For example, if you want to send the
previous query to the program directly, you can do the following:</p>
<pre>&lt;A HREF="/cgi-bin/program.pgm?Name=John&amp;LName=Richard&amp;user=Smith%Company=IBM"&gt;
YourCGI Program&lt;/a&gt;</pre>
<p>The main advantage to the POST method
is that the query length can be unlimited so you do not have to worry about
the client or server truncating data. The query string of the GET method cannot
exceed 8 KB.</p>
</div>
</div>
</div>
<div class="nested1" xml:lang="en-us" id="dataconversionsoncgiinputandoutput"><a name="dataconversionsoncgiinputandoutput"><!-- --></a><h2 class="topictitle2">Data Conversions on CGI Input and Output</h2>
<div><p>The server can perform ASCII to EBCDIC conversions before sending data
to CGI programs. This is needed because the Internet is primarily ASCII-based
and the iSeries™ server
is an extended binary-coded decimal interchange code (EBCDIC) server. The
server can also perform EBCDIC to ASCII conversions before sending data back
to the browser. You must provide data to a CGI program through environment
variables and standard-input (stdin). HTTP and HTML specifications allow you
to tag text data with a character set (charset parameter on the Content-Type
header). However, this practice is not widely in use today (although technically
required for HTTP1.0/1.1 compliance). According to this specification, text
data that is not tagged can be assumed to be in the default character set
ISO-8859-1 (US-ASCII). The server correlates this character set with ASCII
coded character set identifier (CCSID) 819.</p>
<p>For more information related to CCSIDs, national language support, and
international application development, see the Globalization topic in the
iSeries Information Center.</p>
</div>
<div class="nested2" xml:lang="en-us" id="httpserverpoweredbyapache"><a name="httpserverpoweredbyapache"><!-- --></a><h3 class="topictitle3">National Language Support Directives</h3>
<div><p>You can configure HTTP Server (powered by Apache) to control which mode
is used by specifying the CGIConvMode directive in different contexts, such
as server config or directory:</p>
<pre>CGIConvMode Mode</pre>
<p>Where <var class="varname">Mode</var> is one of the following:</p>
<ul class="simple"><li>BINARY </li>
<li>EBCDIC </li>
<li>EBCDIC_JCD</li>
</ul>
<div class="p">You can configure HTTP Server (powered by Apache) to set the ASCII and
EBCDIC CCSIDs that are used for conversions by specifying the directives DefaultNetCCSID
and CGIJobCCSID in different contexts, such as server config or directory.
For example:<ul><li>DefaultNetCCSID 819</li>
<li> CGIJobCCSID 37 </li>
</ul>
You can configure HTTP Server (powered by Apache) to set the locale environment
variable by specifying the CGIJobLocale in different contexts, such as server
config or directory: <tt>CGIJobLocale /QSYS.LIB/EN_US.LOCALE</tt>.</div>
</div>
</div>
<div class="nested2" xml:lang="en-us" id="cgienvironmentvariables"><a name="cgienvironmentvariables"><!-- --></a><h3 class="topictitle3">CGI Environment Variables</h3>
<div><p>In addition, the system provides the following CGI environment variables
to the CGI program:</p>
<ul><li>CGI_MODE - which input conversion mode the server is using (%%MIXED%%,
%%EBCDIC%%, %%BINARY%%, %%EBCDIC_JCD%%, EBCDIC, BINARY, or EBCDIC_JCD)</li>
<li>CGI_ASCII_CCSID - from which ASCII CCSID was used to convert the data</li>
<li>CGI_EBCDIC_CCSID - which EBCDIC CCSID the data was converted into</li>
<li>CGI_OUTPUT_MODE - which output conversion mode the server is using (%%MIXED%%,
%%EBCDIC%%, %%BINARY%, EBCDIC, or BINARY)</li>
<li>CGI_JOB_LOCALE - which locale to use in the CGI program. This environment
variable is set only if the CGIJobLocale directive is set. </li>
</ul>
<p>The supported environment variables for HTTP Server are can be found in
the IBM<sup>®</sup> iSeries
Information Center. The environment variables have been divided into two groups:
Non-SSL and SSL.</p>
</div>
</div>
<div class="nested2" xml:lang="en-us" id="cgiinputconversionmodes"><a name="cgiinputconversionmodes"><!-- --></a><h3 class="topictitle3">CGI Input Conversion Modes</h3>
<div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><caption>Table 1. Conversion action for text in CGI Stdin. This table summarizes the type of conversion that is performed by the
server for each CGI mode.</caption><thead align="left"><tr><th valign="top" width="26.120857699805068%" id="d0e165">CGI_MODE</th>
<th valign="top" width="14.814814814814813%" id="d0e167">Conversion</th>
<th valign="top" width="12.280701754385964%" id="d0e169">Stdin encoding</th>
<th valign="top" width="15.009746588693956%" id="d0e171">Environment variable</th>
<th valign="top" width="17.15399610136452%" id="d0e173">Query_String encoding</th>
<th valign="top" width="14.619883040935672%" id="d0e175">argv encoding</th>
</tr>
</thead>
<tbody><tr><td valign="top" width="26.120857699805068%" headers="d0e165 ">BINARY or %%BINARY%%</td>
<td valign="top" width="14.814814814814813%" headers="d0e167 ">None</td>
<td valign="top" width="12.280701754385964%" headers="d0e169 ">No conversion</td>
<td valign="top" width="15.009746588693956%" headers="d0e171 ">CGI job CCSID</td>
<td valign="top" width="17.15399610136452%" headers="d0e173 ">No conversion</td>
<td valign="top" width="14.619883040935672%" headers="d0e175 ">No conversion</td>
</tr>
<tr><td valign="top" width="26.120857699805068%" headers="d0e165 ">EBCDIC or %%EBCDIC%%</td>
<td valign="top" width="14.814814814814813%" headers="d0e167 ">CGI NetCCSID to CGI job CCSID</td>
<td valign="top" width="12.280701754385964%" headers="d0e169 ">CGI job CCSID</td>
<td valign="top" width="15.009746588693956%" headers="d0e171 ">CGI job CCSID</td>
<td valign="top" width="17.15399610136452%" headers="d0e173 ">CGI job CCSID</td>
<td valign="top" width="14.619883040935672%" headers="d0e175 ">CGI job CCSID</td>
</tr>
<tr><td valign="top" width="26.120857699805068%" headers="d0e165 ">%%EBCDIC%% or %%EBCDIC_JCD%% with charset tag received</td>
<td valign="top" width="14.814814814814813%" headers="d0e167 ">Calculate target EBCDIC CCSID based on received ASCII
charset tag</td>
<td valign="top" width="12.280701754385964%" headers="d0e169 ">EBCDIC equivalent of received charset</td>
<td valign="top" width="15.009746588693956%" headers="d0e171 ">CGI job CCSID</td>
<td valign="top" width="17.15399610136452%" headers="d0e173 ">CGI job CCSID</td>
<td valign="top" width="14.619883040935672%" headers="d0e175 ">CGI job CCSID</td>
</tr>
<tr><td valign="top" width="26.120857699805068%" headers="d0e165 ">EBCDIC_JCD or %%EBCDIC_JCD%%</td>
<td valign="top" width="14.814814814814813%" headers="d0e167 ">Detect input based on received data. Convert data to
CGI job CCSID</td>
<td valign="top" width="12.280701754385964%" headers="d0e169 ">Detect ASCII input based on received data. Convert data
to CGI job CCSID.</td>
<td valign="top" width="15.009746588693956%" headers="d0e171 ">CGI job CCSID</td>
<td valign="top" width="17.15399610136452%" headers="d0e173 ">Detect ASCII input based on received data. Convert data
to CGI job CCSID.</td>
<td valign="top" width="14.619883040935672%" headers="d0e175 ">Detect ASCII input based on received data. Convert data
to CGI job CCSID</td>
</tr>
<tr><td valign="top" width="26.120857699805068%" headers="d0e165 ">%%MIXED%% (Compatibility mode)</td>
<td valign="top" width="14.814814814814813%" headers="d0e167 ">CGI NetCCSID to CGI job CCSID (receive charset tag is
ignored)</td>
<td valign="top" width="12.280701754385964%" headers="d0e169 ">CGI job CCSIDwith ASCII escape sequence</td>
<td valign="top" width="15.009746588693956%" headers="d0e171 ">CCSID 37</td>
<td valign="top" width="17.15399610136452%" headers="d0e173 ">CCSID 37 with ASCII escape sequence</td>
<td valign="top" width="14.619883040935672%" headers="d0e175 ">CCSID 37 with ASCII escape sequence</td>
</tr>
</tbody>
</table>
</div>
<div class="note"><span class="notetitle">Note:</span> If the directive CGIJobCCSID is present, the CGI job runs under its
specified CCSID value. Otherwise, the DefaultFsCCSID value is used (the default
job CCSID). </div>
<div class="section"><dl><dt class="dlterm">BINARY</dt>
<dd>The BINARY mode, delivers QueryString and stdin to the CGI program in
ASCII, exactly as it was received from the client. The environment variables
are in the CGI job CCSID. If CGIJobCCSID is present the job CCSID has its
value; otherwise, the value associated with DefaultFsCCSID (the default job
CCSID) is used. </dd>
<dt class="dlterm">EBCDIC</dt>
<dd>The EBCDIC mode, delivers all of the information to the CGI program in
the job CCSID. The ASCII CCSID of the QueryString or stdin data is determined
from a charset tag on the content type header if present. If CGIJobCCSID is
present the job CCSID has its value; otherwise, the value associated with
DefaultFsCCSID (the default job CCSID) is used. </dd>
<dt class="dlterm">EBCDIC_JCD</dt>
<dd>The EBCDIC_JCD mode is the same as the EBCDIC mode except that a well-known
Japanese codepage detection algorithm is used to determine the ASCII CCSID
when the charset tag is not present. Japanese browsers can potentially send
data in one of three code pages, JIS (ISO-2022-JP), S-JIS (PC-Windows), or
EUC (UNIX<sup>®</sup>).</dd>
</dl>
</div>
</div>
</div>
<div class="nested2" xml:lang="en-us" id="dbcsconsiderations"><a name="dbcsconsiderations"><!-- --></a><h3 class="topictitle3">DBCS Considerations</h3>
<div><p>URL-encoded forms containing DBCS data could contain ASCII octets that
represent parts of DBCS characters. The server can only convert non-encoded
character data. This means that it must un-encode the double-byte character
set (DBCS) stdin and QUERY_STRING data before performing the conversion. In
addition, it has to reassemble and re-encode the resulting EBCDIC representation
before passing it to the CGI program. Because of this extra processing, CGI
programs that you write to handle DBCS data may choose to receive the data
as BINARY and perform all conversions to streamline the entire process.</p>
<p><strong>Using the EBCDIC_JCD mode</strong>: The EBCDIC_JCD mode determines what character
set is being used by the browser for a given request. This mode is also used
to automatically adjust the ASCII/EBCDIC code conversions used by the web
server as the request is processed.</p>
<p>After auto detection, the %%EBCDIC_JCD%% or EBCDIC_JCD mode converts the
stdin and QUERY_STRING data from the detected network CCSID into the correct
EBCDIC CCSID for Japanese. The default conversions configured for the CGI
job are overridden. The DefaultFsCCSID directive or the -fsccsid startup parameter
specifies the default conversions. The startup FsCCSID must be a Japanese
CCSID. Alternately, the CGIJobCCSID can be set to a Japanese CCSID.</p>
<p>The possible detected network code page is Shift JIS, eucJP, and ISO-2022-JP.
The following are the associated CCSIDs for each code page:</p>
<pre>Shift JIS
=========
CCSID 932: IBM PC (old JIS sequence, OS/2 J3.X/4.0, IBM Windows J3.1)
CCSID 942: IBM PC (old JIS sequence, OS/2 J3.X/4.0)
CCSID 943: MS Shift JIS (new JIS sequence, OS/2 J4.0
MS Windows J3.1/95/NT)
eucJP
=====
CCSID 5050: Extended UNIX Code (Japanese)
ISO-2022-JP
===========
CCSID 5052: Subset of RFC 1468 ISO-2022-JP (JIS X 0201 Roman and
JIS X 0208-1983) plus JIS X 0201 Katakana.
CCSID 5054: Subset of RFC 1468 ISO-20220JP (ASCII and JIS X 0208-1983)
plus JIS X 0201 Katakana.</pre>
<p>The detected network CCSID is available to the CGI program. The CCSID is
stored in the CGI_ASCII_CCSID environment variable. When JCD can not detect,
the default code conversion is done as configured (between NetCCSID and FsCCSID
or CGIJobCCSID).</p>
<p>Since the code page of Stdin and QUERY_STRING are encoded according to
the web clients outbound code page, we recommend using the following configuration
value combinations when you use the EBCDIC_JCD or %%EBCDIC_JCD%% mode.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><caption>Table 2. </caption><thead align="left"><tr valign="bottom"><th valign="bottom" id="d0e293">Startup (FsCCSID)/CGI job CCSID (CGIJobCCSID)</th>
<th valign="bottom" id="d0e295">Startup (DefaultNetCCSID)/CGI Net CCSID (DefaultNetCCSID)</th>
<th valign="bottom" id="d0e297">Description</th>
</tr>
</thead>
<tbody><tr><td valign="top" headers="d0e293 ">5026/5035 (See note 4)</td>
<td valign="top" headers="d0e295 ">943 Default:</td>
<td valign="top" headers="d0e297 ">MS Shift JIS</td>
</tr>
<tr><td valign="top" headers="d0e293 ">5026/5035 (See note 4)</td>
<td valign="top" headers="d0e295 ">942 Default</td>
<td valign="top" headers="d0e297 ">IBM PC</td>
</tr>
<tr><td valign="top" headers="d0e293 ">5026/5035 (See note 4)</td>
<td valign="top" headers="d0e295 ">5052/5054 Default</td>
<td valign="top" headers="d0e297 ">ISO-2022-JP</td>
</tr>
</tbody>
</table>
</div>
<p>Using CCSID 5050(eucJP) for the startup NetCCSID, is not recommended. When
5050 is specified for the startup NetCCSID, the default code conversion is
done between FsCCSID and 5050. This means that if JCD cannot detect a code
page, JCD returns 5050 as the default network CCSID. Most browsers use a
default outbound code page of Shift JIS or ISO-2022-JP, not eucJP.</p>
<p>If the web client sends a charset tag, JCD gives priority to the charset
tag. Stdout function is the same. If the charset/ccsid tag is specified in
the Content-Type field, stdout gives priority to charset/ccsid tag. Stdout
also ignores the JCD detected network CCSID.</p>
<div class="note"><span class="notetitle">Notes:</span> <ol><li><span id="dbcsconsiderations__note1"><a name="dbcsconsiderations__note1"><!-- --></a>If startup NetCCSID is 932 or 942, detected network, Shift
JISs CCSID is the same as startup NetCCSID. Otherwise, Shift JISs CCSID
is 943.</span><pre>Startup NetCCSID Shift JIS (JCD detected CCSID)
---------------- ------------------------------
932 932
942 942
943 943
5052 943
5054 943
5050 943</pre>
</li>
<li><span id="dbcsconsiderations__note2"><a name="dbcsconsiderations__note2"><!-- --></a>Netscape Navigator 3.x sends the alphanumeric characters
by using JIS X 0201 Roman escape sequence (CCSID 5052) for ISO-2022-JP. Netscape
Communicator 4.x sends the alphanumeric characters by using ASCII escape sequence
(CCSID 5054) for ISO-2022-JP.</span></li>
<li><span id="dbcsconsiderations__note3"><a name="dbcsconsiderations__note3"><!-- --></a>JCD function has the capability to detect EUC and SBCS
Katakana, but it is difficult to detect them. IBM recommends that you do not
use SBCS Katakana and EUC in CGI.</span></li>
<li><span id="dbcsconsiderations__note4"><a name="dbcsconsiderations__note4"><!-- --></a>CCSID 5026 assigns lowercase alphabet characters on a special
code point. This often causes a problem with lowercase alphabet characters</span>.
To avoid this problem, do one of the following:<ul><li>Do not use lowercase alphabet literals in CGI programs if the FsCCSID
is 5026.</li>
<li>Use CCSID 5035 for FsCCSID.</li>
<li>Use the Charset/CCSID tag as illustrated in the following excerpt of a
CGI program:<pre>main(){
printf("Content-Type: text/html; Charset=ISO-2022-JP\n\n");
...
}</pre>
</li>
<li>Do the code conversions in the CGI program. The following sample ILE C
program converts the literals into CCSID 930 (the equivalent to CCSID 5026):<pre>main(){
printf("Content-Type: text/html\n\n);
#pragama convert(930)
printf("&lt;html&gt;");
printf("This is katakana code page\n");
#pragama convert(0)
...
}</pre>
</li>
<li><span id="dbcsconsiderations__note5"><a name="dbcsconsiderations__note5"><!-- --></a>When the web client sends a charset tag, the network CCSID
becomes the ASCII CCSID associated with Multipurpose Internet Mail Extensions
(MIME) charset header. The charset tag ignores the JCD detected CCSID. When
the Charset/CCSID tag is in the Content-Type header generated by the CGI program,
the JCD-detected CCSID is ignored by this Charset/CCSID. Stdout will not perform
a conversion if the charset is the same as the MIMEs charset. Stdout will
not perform a conversion if the CCSID is ASCII. Stdout will perform code conversion
if the CCSID is EBCDIC. Because the environment variables and stdin are already
stored in job CCSID, ensure that you are consistent between the job CCSID
and the Content-Type headers CCSID.</span></li>
</ul>
</li>
</ol>
</div>
</div>
</div>
<div class="nested2" xml:lang="en-us" id="cgioutputconversionmodes"><a name="cgioutputconversionmodes"><!-- --></a><h3 class="topictitle3">CGI Output Conversion Modes</h3>
<div><p>The CgiConv conversion mode includes an output mode. This section explains
CGI output conversion modes in more detail.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><caption>Table 3. Conversion action and charset tag generation
for text in CGI Stdout. This table summarizes the type of conversion
that is performed and the charset tag that is returned to the browser by the
server.</caption><thead align="left"><tr><th valign="top" width="49.122807017543856%" id="d0e375">CGI Stdout CCSID/Charset in HTTP header</th>
<th valign="top" width="23.157894736842106%" id="d0e377">Conversion action</th>
<th valign="top" width="27.719298245614034%" id="d0e379">Server reply charset tag</th>
</tr>
</thead>
<tbody><tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">EBCDIC CCSID/Charset</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">Calculate EBCDIC to ASCII conversion based on supplied
EBCDIC CCSID/Charset</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">Calculated ASCII charset</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">ASCII CCSID/Charset</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">No conversion</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">Stdout CCSID/Charset as Charset</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">65535</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">No conversion</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">None</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">None (CGIConvMode= %%BINARY%%, %%BINARY/MIXED%%, or
%%BINARY/EBCDIC%%)</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">Default Conversion - job CCSID to NetCCSID</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">NetCCSID as charset</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">None (CGIConvMode= BINARY or %%BINARY/BINARY%%)</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">No conversion</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">None</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">None (CGIConvMode= EBCDIC, %%EBCDIC%%, %%EBCDIC/MIXED%%,
or %%EBCDIC/EBCDIC%%)</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">Default Conversion - job CCSID to NetCCSID</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">NetCCSID as charset</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">None (CGIConvMode= EBCDIC, EBCDIC_JCD, %%EBCDIC%%, %%EBCDIC/MIXED%%,
or %%EBCDIC/EBCDIC%% with charset tag received on HTTP request) </td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">Use inverse of conversion calculated for stdin</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">Charset as received on HTTP request</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">None (CGIConvMode= %%EBCDIC_JCD%%, %%EBCDIC_JCD/MIXED%%,
or %EBCDIC_JCD/EBCDIC%%)</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">Use inverse of conversion calculated by the Japanese
codepage detection</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">ASCII CCSID as charset</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">None (CGIConvMode= %%MIXED%% or %%MIXED/MIXED%%)</td>
<td valign="top" width="23.157894736842106%" headers="d0e377 ">Default Conversion - job CCSID to NetCCSID</td>
<td valign="top" width="27.719298245614034%" headers="d0e379 ">None (compatibility mode)</td>
</tr>
<tr><td valign="top" width="49.122807017543856%" headers="d0e375 ">Invalid</td>
<td colspan="2" valign="top" headers="d0e377 d0e379 ">CGI error 500 generated by server</td>
</tr>
</tbody>
</table>
</div>
<p>HTTP Server (powered by Apache) also set an environment variable CGI_OUTPUT_MODE
to reflect the setting for the CGI output mode. It contains the CGI output
conversion mode the server is using for this request. Valid values are %%EBCDIC%%,
%%MIXED%%, %%BINARY%%, EBCDIC, BINARY, or EBCDIC_JCD. The program can use
this information to determine what conversion, if any, the server performs
on CGI output.</p>
<div class="section"><h4 class="sectiontitle">HTTP Server (powered by Apache)</h4><dl><dt class="dlterm">BINARY</dt>
<dd>In this mode HTTP header output is in CCSID 819 with the escape sequences
also being the ASCII representative of the ASCII code point. An example of
a HTTP header that may contain escape sequences is the Location header. The
body is always treated as binary data and the server performs no conversion.</dd>
<dt class="dlterm">EBCDIC</dt>
<dd>In this mode HTTP header output is assumed to be in the CGI job CCSID,
unless otherwise specified in a charset or CCSID tag by the CGI program. However,
the escape sequence must be the EBCDIC representative of the EBCDIC code point
for the 2 characters following the ″%″ in the escape sequence. An example
of a HTTP header that may contain escape sequences is the Location header.
The body (if the mime type is text/*) is assumed to be in the job CCSID, unless
otherwise specified in a charset or CCSID tag by the CGI program. If CGIJobCCSID
is present the CGI job CCSID has its value; otherwise, the value associated
with DefaultFsCCSID (the default job CCSID) is used.</dd>
<dt class="dlterm">EBCDIC_JCD</dt>
<dd>In this mode HTTP header output is assumed to be in the job CCSID, unless
otherwise specified in a charset or CCSID tag by the CGI program. However,
the escape sequence must be the EBCDIC representation of the EBCDIC code point
for the 2 characters following the ″%″ in the escape sequence. An example
of a HTTP header that may contain escape sequences is the Location header.
The body (if the mime type is text/*) is assumed to be in the job CCSID, unless
otherwise specified in a charset or CCSID tag by the CGI program. If CGIJobCCSID
is present the job CCSID has its value; otherwise, the value associated with
DefaultFsCCSID (the default job CCSID) is used.</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="nested1" xml:lang="en-us" id="returningoutputfromtheserver"><a name="returningoutputfromtheserver"><!-- --></a><h2 class="topictitle2">Returning Output from the Server</h2>
<div><p>When the CGI program is finished, it passes the resulting response to the
server by using standard output (stdout). The server interprets the response
and sends it to the browser.</p>
<p>A CGI program writes a CGI header that is followed by an entity body to
standard output. The CGI header is the information that describes the data
in the entity body. The entity body is the data that the server sends to the
client. A single newline character always ends the CGI header. The newline
character for ILE C is \n. For ILE RPG or ILE COBOL, it is hexadecimal 15.
The following are some examples of Content-Type headers:</p>
<pre>Content-Type: text/html\n\n
Content-Type: text/html; charset=iso-8859-2\n\n</pre>
<p>If the response is a static document, the CGI program returns either the
URL of the document using the CGI Location header or returns a Status header.
The CGI program does not have an entity body when using the Location header.
If the host name is the local host, HTTP Server will retrieve the specified
document that the CGI program sent. It will then send a copy to the web browser.
If the host name is not the local host, the HTTP processes it as a redirect
to the web browser. For example:</p>
<pre>Location: http://www.acme.com/products.html\n\n</pre>
<p>The Status header should have a Content_Type: and a Status in the CGI header.
When Status is in the CGI header, an entity body should be sent with the data
to be returned by the server. The entity body data contains information that
the CGI program provides to a client for error processing. The Status line
is the Status with an HTTP 3 digit status code and a string of alphanumeric
characters (A-Z, a-z, 0-9 and space). The HTTP status code must be a valid
3 digit number from the HTTP/1.1 specification.</p>
<div class="note"><span class="notetitle">Note:</span> The newline character \n ends the CGI header.</div>
<pre>CONTENT-TYPE: text/html\n
Status: 600 Invalid data\n
\n
&lt;html&gt;&lt;head&gt;&lt;title&gt;Invalid data&lt;/title&gt;
&lt;/head&gt;&lt;body&gt;
&lt;h1&gt;Invalid data typed&lt;/h1&gt;
&lt;br&gt;&lt;pre&gt;
The data entered must be valid numeric digits for id number
&lt;br&gt;&lt;/pre&gt;
&lt;/body&gt;&lt;/html&gt;</pre>
</div>
</div>
<div class="nested1" xml:lang="en-us" id="howcgiprogramswork"><a name="howcgiprogramswork"><!-- --></a><h2 class="topictitle2">How CGI Programs Work</h2>
<div><p>Most CGI programs include the following three stages:</p>
<ul><li>Parsing CGI programs</li>
<li>Data manipulation within a CGI program</li>
<li>Response generation by a CGI program</li>
</ul>
<div class="note"><span class="notetitle">Note:</span> Any CGI program with a name that begins with nph_ is considered a no
parse header CGI program. This means that the server does no conversions on
the data and adds no headers back in the response from the CGI program. The
CGI programmer is in total control and is responsible for parsing the request
and then sending all of the necessary headers back with the response.</div>
</div>
<div class="nested2" xml:lang="en-us" id="parsing"><a name="parsing"><!-- --></a><h3 class="topictitle3">Parsing</h3>
<div><p>Parsing is the first stage of a CGI program. In this stage, the program
takes the data from QUERY_STRING environment variable, command line arguments
using argv() or standard input. When the method is GET, the system reads the
data from the QUERY_STRING environment variable or command line arguments
by using argv(). There is no way to determine the length of data in QUERY_STRING.
The system encodes the QUERY_STRING data in the request header.</p>
<p>An example of data read in the QUERY_STRING variable (%%MIXED%% mode):</p>
<pre>NAME=Eugene+T%2E+Fox&amp;ADDR=etfox%40ibm.net&amp;INTEREST=RCO</pre>
<p>Parsing breaks the fields at the ampersands and decodes the ASCII hexadecimal
characters. The results look like this:</p>
<pre>NAME=Eugene T. Fox
ADDR=etfox@ibm.net
INTEREST=RCO</pre>
<p>You can use the QtmhCvtDb API to parse the information into a structure.
The CGI program can refer to the structure fields. If using %%MIXED%% input
mode, the “%xx” encoding values are in ASCII and must be converted into the
“%xx” EBCDIC encoding values before calling QtmhCvtDb. If using %%EBCDIC%%
mode, the server will do this conversion for you. The system converts ASCII
“%xx” first to the ASCII character and then to the EBCDIC character. Ultimately,
the system sets the EBCDIC character to the “%xx” in the EBCDIC CCSID.</p>
<p>When the method is POST, the system reads the data from standard input.
Before the CGI attempts to read standard input, it must check environment
variables REQUEST_METHOD and CONTENT_LENGTH. Read standard input only when
the REQUEST_METHOD is POST. The read must specify no more than CONTENT_LENGTH
bytes. Attempts to specify more than CONTENT_LENGTH bytes on reading standard
input are not defined.</p>
</div>
</div>
<div class="nested2" xml:lang="en-us" id="datamanipulation"><a name="datamanipulation"><!-- --></a><h3 class="topictitle3">Data manipulation</h3>
<div><p>Data manipulation is the second stage of a CGI program. In this stage,
the program takes the parsed data and performs the appropriate action. For
example, a CGI program designed to process an application form might perform
one of the following functions:</p>
<ol><li>Take the input from the parsing stage</li>
<li>Convert abbreviations into more meaningful information</li>
<li>Plug the information into an e-mail template</li>
<li>Use SNDDST to send the e-mail.</li>
</ol>
</div>
</div>
<div class="nested2" xml:lang="en-us" id="responsegeneration"><a name="responsegeneration"><!-- --></a><h3 class="topictitle3">Response generation</h3>
<div><p>Response generation is the final stage of a CGI program. In this stage,
the program formulates its response to the web server, which forwards it to
the browser. The response contains MIME headers that vary depending on the
type of response. With a search, the response might be the URLs of all the
documents that met the search value. With a request that results in e-mail,
the response might be a message that confirms that the system actually sent
the e-mail.</p>
</div>
</div>
</div>
</body>
</html>