Developing a hello world application from scratch
The next chapter illustrates the steps to create a hello world application from scratch, compile it, deploy it and eventually debug it.
Writing the source
Programs for the web are standard COBOL programs. The following source code produces a screen with a button with "Hello World" inside:
PROGRAM-ID. HELLO. SCREEN SECTION. 01 SCREEN1. 03 PUSH-BUTTON LINE 4 COL 4 SIZE 15 CELLS TITLE "Hello World" EXCEPTION-VALUE 100 . PROCEDURE DIVISION. MAIN. DISPLAY STANDARD GRAPHICAL WINDOW. DISPLAY SCREEN1. ACCEPT SCREEN1 ON EXCEPTION CONTINUE. |
Compiling the source
Since we plan to debug the program after the deployment, we'll use the -d option.
The -wd2 option is also used to be sure that our program is compatible with WebDirect.
Creating the configuration file
In order to run with WebDirect we must instruct the program to use a specific guifactory class.
In addition, the license codes for the isCOBOL Framework and WebDirect must be provided, so our configuration file will look like this:
iscobol.guifactory.class=com.iscobol.gui.client.zk.GuiFactoryImpl iscobol.license.2021=XXXXXXXXXXXXXXXXXXXXXXX iscobol.eis.license.2021=XXXXXXXXXXXXXXXXXXXXXXX |
The configuration file will be placed between program classes in the webapp directories. However, the configuration is also loaded from \etc directory and from the user home directory depending on the drive where Tomcat was started and on the user that owns its process.
Deploying in Tomcat
The easiest way to deploy a new web app is to:
• Make a copy of the tomcat/webapps/webdirect folder and rename the copy to the name of your choice (i.e. 'test')
Note - the subfolders "pdf" and "upload" are specific for the WebDirect sample; you can either delete them or rename them, depending on your needs. The other subfolders instead should be left unchanged.
• Add your class files to one of the following:
o one of the folders listed in iscobol.code_prefix configuration property
or, if iscobol.code_prefix is not set,
o the WEB-INF/classes folder
o a jar file placed in the WEB-INF/lib folder
• Add your properties to the WEB-INF/classes/iscobol.properties file
• Restart Tomcat
Running the application
Run the HELLO program from a web browser using the following URL: http://127.0.0.1:8080/test/zk/IsMainZK?PROGRAM=HELLO to have:
Debugging
In order to debug the web application
• Programs must be compiled with -d option
• The following entry must appear in the configuration
• The Remote Debugger feature is used
When you connect to the page of your application you will see a blank page. It means that the web application is waiting for the Debugger to connect. Launch the following command to use the Debugger:
iscrun -J-Discobol.debug.code_prefix=sourcePath -d -r serverIp |
Where:
• sourcePath is the list of paths where program source code and copyfiles can be found
• serverIp is the ip (or name) of the web-server where the web application is running, in our case: 127.0.0.1
If everything has been done correctly, you should see the web page show up while you debug the DISPLAY statements.