|
7. |
Q:
Can you summarize the steps I have to go through
in writing my first CGI?
A:
Suppose the following:
- your images (gif's, jpg's, etc.) will reside
in an IFS directory named myobjlib
- your source library is named MYSRCLIB
- your object library (the one to contain
your dynamic HTML scripts, your CGI programs,
and Mel Rothman's service program CGISRVPGM)
is named MYOBJLIB
- your first CGI program is named MYCGI1
Proceed as follow:
- Add HTTP directives
to your http instance configuration
(I suggest you use instance default
which is related to configuration member
config) in the following way
- type command
wrkhttpcfg
to edit the http configuration member
- add the following directives at the top
of the configuration member
Map /myobjlibh/* /QSYS.LIB/MYOBJLIB.LIB/HTMLSRC.FILE/*
Pass /QSYS.LIB/MYOBJLIB.LIB/HTMLSRC.FILE/*
Pass /myobjlib/*
Exec /myobjlibp/* /QSYS.LIB/MYOBJLIB.LIB/*
|
-the first directive allows you to write
in your HTML (or in the browser command line)
/myobjlibh/ instead of
/QSYS.LIB/MYOBJLIB.LIB/HTMLSRC.FILE/
thus saving keystrokes (and related errors)
-the second directive allows HTTP server
to access whatever member in file
HTMLSRC in library
MYOBJLIB
-the third directive allows HTTP server
to access whatever file in the directory
/myobjlib
-the fourth directive allows HTTP server
to execute CGI's in library
MYOBJLIB, provided
you specify the path
/myobjlibp.
As an example, to execute program
MYCGI1 in library
MYOBJLIB
you should mention it as
/myobjlibp/mycgi1.pgm
- roll down the http directives until you find
the following directives
# enable get
# enable post
|
and make sure to remove the # symbol
(comment symbol) in those two lines.
After updating the http directives, restart
your http server by entering command
endhttpsvr *http
followed by command
strtcpsvr *http
- Set up your CGI source and object libraries
by entering command
CGIDEV2/SETCGILIB SRCLIB(MYSRCLIB) PRDLIB(MYOBJLIB)
.
For information on this command please see
this page.
- Note 1-
Command SETCGILIB,
if run from a user profile with
*CHANGE authority
on the HTTP configuration file
(
QUSRSYS/QATMHTTPC),
generates entries in the
DEFAULT HTTP server configuration member,
so you do not have to do it manually,
as specified in the previous step.
- Obtain a sample external html source
and
a sample CGI RPG source
by using command
CGIDEV2/CRTCGISRC SRCMBR(mycgi1) SRCLIB(mysrclib) PRDLIB(myobjlib)
You may compile the module,
create the CGI program and run it.
Afterwards you may change both the external HTML
and the CGI program to fit your needs.
- Note 1.
To create the module use commnad
CRTRPGMOD
and do not forget to specify
DBGVIEW(*SOURCE).
I would also recomment that you change the default value
of this parameter once for ever entering command
CHGCMDDFT CMD(CRTRPGMOD) NEWDFT('dbgview(*source)')
.
- Note 2.
To create the CGI program, use command
CRTPGM
as specified in the initial comments of the
RPG source.
- Note 3.
To run your CGI, use the instructions
specified in the initial comments of the
RPG source.
If you receive Error 500,
this means that either your program was not found,
or that it bumped out during execution.
In this case, get prepared for debugging reading
this page.
- Note 4. See
this page
for more information on how to divide this script
into record-formats or sections
and on how to define output variables.
|