CGI Programming

I will use
in the following tutorial.

= HTML Generation =

There is a simple trick using classes constructor and destructor to
generate well-formed code:

 Html h;
 	Body b;
 	cout << "Hello World" << endl;
 } // end of body object
 } // end of html object

It guarantees you not to forget any enclosing tags and the scoping fits
well for C++ Code.

However, cgicc uses a state based approach which makes you independent of
blocks, but you need to be aware to have an even number of boolean elements.
Knowing that the use is straight-forward:

 cout << html() << body() << "Hello World" << body() << html() << endl;

But it gets more nice and comfortable when passing an HTMLElement in the

 cout << html(body("Hello World")) << endl;

= QueryString =

The tutorials deal long with parsing form data, but they do not explain
how to deal with QueryString.

The QueryString is parsed by the Cgicc Object too and the Elements are

Having the query string:


with the code:

 	form_iterator name = cgi.getElement("action");
 	while (name != cgi.getElements().end()) {
 		cout << p() << "name: " << name->getName() << " value: " << **name << p() << endl;

the output will be something like:

 name: action value: 4
 name: test value: sers

Of course you can also use getIntegerValue and so in of FormEntry, but a lexical_cast is from the
string is also possible. While name->getIntegerValue() silently passes 0, lexical_cast throws
an exception, which should be done because no more useful processing can be done in most cases.


CGI Specification:

CGI Programming FAQ:

Fr Jul 30 13:54:24 CEST 2021
patent_button.gif valid-html401.png elektra.jpg fsfe-logo.png valid-css.png vim.gif anybrowser.gif