There may be cases, where a page created from a CGI
(dynamic page)
- is frequently accessed
- requires some relevant processing,
thus providing a rather long response time
- and its contents may change at unpredictable
times
Examples of such cases could be:
-
our page about
"our subscribers per country"
- many other statistics pages
One interesting way to serve such requests
is to have some dynamic processes
generating static pages:
- user response is much faster
- computer load much lower
- the generation of a static page may be
triggered by an event or scheduled
at a regular time interval
Implementing such a process is quite easy:
you have to write a batch program similar to a CGI
and gear it to some event or schedule.
Here is how you may write such a program:
- Develop the external HTML as usual for
a CGI program, but
- do not insert the initial http header
Content-type: text/html
(you are going to build a static page)
- Develop the program as if it were a CGI program using our
CGISRVPGM2 service program
(you may use our command
to create an initial sample CGI source)
- avoid reading and parsing the input string
(drop our cgidev2/crtcgisrc generated statement
/copy .../qrpglesrc,prolog1/2/3
)
- instead of sending the html buffer to the client
with the instruction
callp wrtsection('*fini')
save it as an IFS stream file using the subrocedure
WrtHtmlToStmf():
D Stmf s 512 varying
D inz('/web/dynapage1.html')
D CCSID s 10i 0 inz(819)
D rc s 10i 0
* If "CCSID" parameter omitted, the CCSID is assigned by the
* system (the CCSID of the job is used).
C if CCSID > 0
C eval rc = WrtHtmlToStmf(Stmf:CCSID)
C else
C eval rc = WrtHtmlToStmf(Stmf)
C endif |
Notes:
- The filename portion in the "stream file" variable supports a maximum length of 245
bytes.
- Create the program with
actgrp(*new).
- Subprocedure WrtHtmlToStmf() clears the output buffer before returning to the user program.
This is done to allow the user program to create more than one stream file
without overlaying previous output data.
- CCSID 1208 should be used for UTF-8 Unicode.
For other CCSID's see this page.
- Should you need instead to append the html buffer to
an existing stream file, you must use subprocedure AppHtmlToStmf():
D Stmf s 512 varying
D inz('/web/dynapage1.html')
D rc s 10i 0
C eval rc = AppHtmlToStmf(Stmf) |
Example of a dynamic/static page:
- Please
browse the source
of our example program. It would generate a page
containing some random integers.
To run this program:
- addlible cgidev2
- enter command
CGIDEV2/RANDOMNBRS STMF('/cgidev/randomnbrs.htm') CODEPAGE(819)
- Check out the
generated static page.
Error codes.
If subprocedure wrtHtmlToStmf does not complete
normally, it returns a non-zero error code (in field "rc").
Error codes are documented in an
IBM Infocenter separate page.
|