|
htmlCgi
CGI (Common Gateway Interface) server class | [Previous] [Main] [Next] |
| htmlCgi is derived from htmlServer and manages the Common Gateway Interface between the server and the html++ application. The CGI standard is widely support among nearly all web server vendors. htmlCgi is commonly used on Unix platforms but is also compatible with Windows-based servers such as O'Reilly WebSite and others.
| |
|
| |
| The counterpart class to htmlCgi is htmlISAPI, which interfaces html++ applications directly to any ISAPI-compliant web server, such as Microsoft IIS.
| |
|
| |
| htmlCgi and htmlISAPI behave and are used identically to their htmlServer parent class, with the only exception being the constructor arguments.
| |
|
| |
| #include <dcmicro/htmlpp/cgi.h>
| |
|
| |
| |
|
| |
| htmlServer, htmlISAPI, CNVList, htmlForm, htmlInputHidden, htmlCookie
| |
|
| |
| None.
| |
|
| |
| htmlCgi()
| |
| Constructs an empty, uninitialized cgi object, loading environment variables into the member variables. This constructor is rarely used, and must be followed by a manual call to the base-class Initialize() method.
| |
|
| |
| htmlCgi( istream& is )
| |
| Constructs the cgi object from the is input stream, loading environment variables into the member variables. Implicitly executes the Initialize() method, passing along is as the argument. Typically, the standard C++ cin input stream object is used.
| |
|
| |
| virtual ~htmlCgi()
| |
| Destroys the object.
| |
|
| |
| Refer to htmlServer.
| |
| The following two programs illustrate use of the htmlCgi class to pass data from a form (generated using html++, though it could be any HTML form document) to a server-side html++ application. The application then processes the data and outputs a dynamically-generated page.
| |
|
| |
| // program 1: Create the data input form
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| int main( void )
| |
| {
| |
| htmlCgi server ;
| |
| htmlPage page( "html++ form input example" ) ;
| |
|
| |
| // Create a form, setting the action
| |
| // statement to "/cgi-bin/formdemo"
| |
| htmlForm form( "/cgi-bin/formdemo" );
| |
|
| |
| // Set up input areas for last name,
| |
| // first name, and email address. Allow
| |
| // up to 20 characters for the names,
| |
| // and 30 characters for the email.
| |
| form << "Last Name: "
| |
| << htmlInputText( "lname", 20 )
| |
| << htmlBreak() ;
| |
|
| |
| form << "First Name: "
| |
| << htmlInputText( "fname", 20 )
| |
| << htmlBreak() ;
| |
|
| |
| form << "Email address: "
| |
| << htmlInputText( "email", 30 )
| |
| << htmlBreak() ;
| |
|
| |
| // Add a submit button with a custom label
| |
| form << htmlCenter( htmlInputSubmit("Press to continue") );
| |
|
| |
| page << form ;
| |
|
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| // program 2: formdemo.cpp - Process the form data
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| int main( void )
| |
| {
| |
| htmlPage page( "html++ formdemo.cpp application" ) ;
| |
|
| |
| // Construct an htmlCgi object to receive
| |
| // the CGI form data from standard input.
| |
| htmlCgi server( cin ) ;
| |
|
| |
| // Output a few data items from the
| |
| // server environment.
| |
| page << "Server_Software: " << server.Server_Software
| |
| << htmlBreak()
| |
| << "Server_Name: " << server.Server_Name
| |
| << htmlBreak()
| |
| << "Gateway_Interface: " << server.Gateway_Interface
| |
| << htmlBreak()
| |
| << "Request_Method: " << server.Request_Method
| |
| << htmlBreak()
| |
| << "Remote_Host: " << server.Remote_Host
| |
| << htmlParagraph() ;
| |
|
| |
| // Output all CGI data from the form
| |
| String name ;
| |
| String value ;
| |
| Boolean good_data = server.Enumerate( name, value, TRUE ) ;
| |
| while ( good_data )
| |
| {
| |
| page << htmlBold( name )
| |
| << " : "
| |
| << value
| |
| << htmlBreak() ;
| |
|
| |
| // loop for next form field
| |
| good_data = server.Enumerate( name, value ) ;
| |
| }
| |
|
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| Content-Type: text/html
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ form input example</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| <FORM ACTION="/cgi-bin/formdemo" METHOD="POST">
| |
| Last Name: <INPUT TYPE="TEXT" NAME="lname" SIZE="20"><BR>
| |
| First Name: <INPUT TYPE="TEXT" NAME="fname" SIZE="20"><BR>
| |
| Email address: <INPUT TYPE="TEXT" NAME="email" SIZE="30"><BR>
| |
| <CENTER><INPUT TYPE="SUBMIT" VALUE="Press to continue"></CENTER></FORM>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
| |
|
| |
|
| |
|
| |
| Content-Type: text/html
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ formdemo.cpp application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| Server_Software: Stronghold/2.0.1 Apache/1.2b11<BR>
| |
| Server_Name: www.dcmicro.com<BR>
| |
| Gateway_Interface: CGI/1.1<BR>
| |
| Request_Method: POST<BR>
| |
| Remote_Host: rangelan.connectup.com<P></P>
| |
| <B>lname</B> : Smith<BR>
| |
| <B>fname</B> : John<BR>
| |
| <B>email</B> : jsmith@anywhere.com<BR>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
| |
