In this final chapter, we’ll look at how to create an Active Server Page (ASP) that will invoke our FILEIO5 COM Sever module from a Web Browser.
Because Visual Basic Script is the default scripting engine for ASP pages, our previous Visual Basic experience will prove invaluable in creating an ASP page.
Creating an ASP page to instantiate the FILEIO5 class and invoke its methods is a very straightforward process.
The resulting ASP page will be named “fujcom.asp” and is shown in Figure 5.1.
<% Language=VBScript%> <% Set FILEIO_PTR = Server.CreateObject("FILEIO5.FILEIO5") Return_Status = FILEIO_PTR.OPEN_FILE() If Return_Status = 0 Then String1 = "<P>" Do While Return_Status = 0 Return_Status = FILEIO_PTR.READ_FILE(Return_Record) If Return_Status = 0 Then String1 = String1 & Return_Record & "</P><P>" End If Loop Return_Status = FILEIO_PTR.CLOSE_FILE() End If Set FILEIO_PTR = Nothing %> <HTML> <HEAD> <TITLE>NetCOBOL COM Server Example</TITLE> </HEAD> <BODY> <H3><Center>Fujtisu COBOL COM Server Returned:</Center></H3> <Center> <% Response.Write String1 %> </Center> </BODY> </HTML>
Figure 5.1 The fujcom.asp page’s source code
If you review the ASP page’s source code shown in Figure 5.1, you’ll note that it is similar to the source code created in the Visual Basic project in the previous chapter with the following exceptions:
VB Script is the language in use in the ASP page. VB Script automatically defines and allocates data types, so DIM statements are not required.
We call the FILEIO5 COM Server’s methods in the same manner we called them from our previous Visual Basic project.
The loop logic has been changed to create a single string named “String1” and to append each read record onto the end of it with appropriate HTML syntax to create a new paragraph for each record read.
Once all records are read and concatenated onto the String1 data item using the READ_FILE method, we close the file by calling the CLOSE_FILE method. We then release the FILEIO5 object by setting its pointer to nothing, just as we did in the previous Visual Basic application.
We use the VB script method Response.Write to write our string out in the HTML code that comes after we exit the VB Script routine we coded.
To execute this ASP page, copy it to the root directory of your Internet Server. This is typically the directory named:
C:\inetpub\wwwroot\
Bring up your web browser and enter:
http://www.my.com/fujcom.asp
where: www.my.com is the name of your web domain. You can optionally enter:
http://111.111.111.111/fujcom.asp
where: 111.111.111.111 is the IP address of your web server.
When you execute the fujcom.asp page, you will see the following display in your Web Browser.
Figure 5.2 The fujcom.asp page in a Web Browser
You should now have an understanding of how to instantiate a COBOL COM Server module from an ASP page and access its methods.