I will be writing about the CGI Development Toolkit in a following article, but in this article I want to try to explain what you have to do to get an RPG program to talk to a browser. Based on feedback at conferences, I am convinced that this is one of the major stumbling blocks that RPG programmers have about programming for the Web; they think it is a lot more complicated then it is. Actually, it is a lot (and I mean a lot) easier to write a program for a browser interface then it is for green screen. Yes, there are difficulties, new things to learn and new problems to deal with, but none are as difficult as many imagine. What is an HTTP server?
'); // -->
TTP server. A browser sends an HTTP request to a port on a server. The HTTP server determines if the request is for a static document (in which case the document is returned to the browser) or if the request is for a CGI script (in which case the script is called and it uses APIs to sent data to the HTTP server which sends it to the browser). On the iSeries, an HTTP server is a number of jobs running in the subsystem QHTTPSVR. [TABLE] Figure 1: An HTTP server But how does the HTTP server know if the request is for a static document or a CGI script? The HTTP server is configured to direct requests based on the directory entered in the URL. For example, in the URL as400.midcs.com/cgiseminar/index, it is the directory of cgiseminar that dictates whether it is a request for a static document or a CGI script. How do you configure an HTTP server? Once the administration server is running, you open your browser and enter this URL: where iseriesservername is the name of your iSeries. When you log in, take the option to Create HTTP Server, as shown in Figure 2, and follow the wizard. There is extensive help available, but there are a couple of points worth noting: The name you give the wizard is the name that will be used for the corresponding server jobs in QHTTPSVR, and when testing, do not use the default port of 80 but use a port in the range 1024 to 2000. That means you will have to enter the port number after the server name (as with :2001 in the example above). [TABLE]Figure 2: Creating a HTTP server Once the basic server has been defined, you need to add definitions for the directories. Take the option to run the Add a Directory to the Web wizard. You must indicate if the directory is to serve static web pages or CGI programs, as shown in Figure 3. [TABLE]Figure 3: Add a directory to the Web When defining a CGI directory you specify the serving directory (i.e. the library containing the RPG programs to be called), as shown in Figure 4, and the alias (i.e. the directory name that is entered in the URL), as shown in Figure 5. In other words, when the alias directory is entered, the HTTP server determines that it must call a program in the serving directory (the name of the program is entered after the alias directory). [TABLE]Figure 4: Specify the serving directory [TABLE]Figure 5: Specify the alias When you have added the directory, you can change the URL mapping to save the amount of information that has to be entered in the URL. For example, you don't have to enter the extension of .PGM on the program name, as shown in Figure 6. [TABLE]Figure 6: URL mapping You can have a look at any of the other features (such as security), but this is all you need to start with CGI programming. Start the server You will spend a lot of time stopping and starting servers during testing. A CGI program followed by two carriage return/linefeed characters (hex '15'). The rest of the data is standard HTML. Figure 7: A simple CGI program You can run the program by entering this URL: [TABLE]Figure 8: Output from a CGI program The big difference The conversation is "question and answer". The browser sends a request to the HTTP server (a job running in QHTTPSVR), the server processes the request, the server sends back a Web page and the conversation ends. The next request could go to a different server. Up and running ---------------------------
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iSeries Security - Security Tools, Physical Security and System Security |
| About Us | Contact Us | For Advertisers | For Business Partners | Site Index | RSS |
|
|
|
|||||||