About Your PxPlus Programs |
|
Use the information in this section and the examples throughout this reference documentation as an aid when you create your web applications. See Appendix - HTML Examples.
As output, you can return any data that is valid to the browser. This includes:
Your PxPlus programs can send files to a browser if you set the %content_type="application/octet-stream" and %content_filename$="somefile.ext" and then dump the file into the %print_fn channel (maximum 4096 bytes per WRITE RECORD).
See PxPlus Web Server Variables.
Your PxPlus web application can do virtually anything except interact directly with the user interface. This means you cannot use:
Interaction with the user must be done indirectly through HTML forms or pages that can request information and return resulting responses and data to your program. Your program can construct an HTML page on the fly from the data.
See entry points 9 to 13 in *web/util CALL EntryPoints and Merge Dynamic Data with HTML Templates (*web/merge).
Think of coding for browsers as block mode transmission to a background task. The Web Server sets up a memory-resident logical file using %print _fn. This variable contains the logical file number or channel the Web Server is using for standard output. You dump your data into the memory file by using PRINT, WRITE and other output directives with "(%print_fn)" as the file channel, as in PRINT (%PRINT_FN)DATA. Then, the Web Server transmits the contents for you.
There are a few limits on the amount and type of output you can generate:
The URLs and PxPlus program below illustrate simple raw text requests. Three URL requests are set up in the browser's address field:
http://127.0.0.1:4000/web_text
http://127.0.0.1:4000/web_text;dump
http://127.0.0.1:4000/web_text;list
The simplest method of generating a report is by using the %raw_text flag, as in the PxPlus program below. Notice the WEB_TEXT entrypoint line labels which were requested in the URLs above. The task handler starts executing each of the three requests at its respective executable line or label entrypoint (0010 , DUMP: and LIST:) below.
0010 ! WEB_TEXT (Report Style Output in Raw Text):
0020 LET %RAW_TEXT=1,%RAW_TITLE$="Example: Raw Text Output"
0030 LET C=HFN; OPEN (C,IOL=*)"CSTFILE"
0040 PRINT (%PRINT_FN)@(1),"CustID",@(20),"Customer Name",'LF'
0050 LOOP:
0060 READ (C,END=DONE)
0070 PRINT (%PRINT_FN)@(1),CST_ID$,@(20),CST_NAME$
0080 GOTO LOOP
0090 DONE:
0100 CLOSE (C)
0110 END
0120 !
0130 DUMP:
0140 LET %RAW_TEXT=1,%RAW_TITLE$="VARIABLE DUMP FOR WEB_TEXT"
0150 DUMP (%PRINT_FN)
0160 END
0170 !
0180 LIST:
0190 LET %RAW_TEXT=1,%RAW_TITLE$="LISTING OF WEB_TEXT PROGRAM"
0200 LIST (%PRINT_FN)
0210 END
In the next example, two URL requests are set up in the browser's address field:
http://127.0.0.1:4000/web_html
http://127.0.0.1:4000/web_html;list_and_dump
This is a simple example of a PxPlus application which contains code to generate HTML and raw text to illustrate that; since each entrypoint routine (i.e. line 0020 and LIST_AND_DUMP:) stands alone as a separate request, each can have its own styling.
0020 PRINT (%PRINT_FN)"<html><head>"
0030 PRINT (%PRINT_FN)"<title>"+"This is a simple HTML example"+"<title>"
0040 PRINT (%PRINT_FN)"</head><body>"
0050 PRINT (%PRINT_FN)"<h1>"+"This is a simple HTML example"+"<h1><hr><p>"
0060 PRINT (%PRINT_FN)"Welcome to PxPlus Web Server</p>"
0070 PRINT (%PRINT_FN)"<p>This is an HTML output example</p>"
0080 PRINT (%PRINT_FN)"<p>You can use any HTML code as output as long as it "
0090 PRINT (%PRINT_FN)"adheres to standard HTML specifications."
0100 PRINT (%PRINT_FN)"</p><body></html>"
0110 END
0120 !
0130 LIST_AND_DUMP:
0140 LET %RAW_TEXT=1,%RAW_TITLE$="Listing + Variable Dump in Raw Text"
0150 LIST (%PRINT_FN)
0160 PRINT (%PRINT_FN)'FF'
0170 DUMP (%PRINT_FN)
0180 END