What if I told you that the desktop computer you're sitting at right now had everything you needed to create Web browser-based applications that act as a front-end to your iSeries database? What if I told you that you could develop an application using this technology much faster than you could develop the same application in green-screen? Now what if I told you that this feature has been available since 1996? Well, all of this is true about Active Server Pages (ASPs). In this article, we'll explore what ASPs are and why you should be using them. We'll also take a look at the setup requirements and how to create an ASP.
In the Beginning
Microsoft introduced Active Server Pages as a downloadable add-in for its Internet Information Server (IIS) Web server. Today ASP support is built into IIS, which is included as part of the Windows operating system. This means that it's highly likely that the computer you're using right now has the ability to serve ASPs. Let's start out by examining how to configure IIS on your Windows-based PC.
Configuring your PC to run IIS is pretty simple. Start by navigating to the Windows Control Panel and selecting Add/Remove Programs. Next, click on the link on the left side of the screen labeled Add/Remove Windows Components. When the Windows Components Wizard dialog comes up, select the checkbox next to Internet Information Server (IIS) as shown in Figure 1. (If this box is already selected, IIS is already installed.)
Figure 1: Select this checkbox to install IIS on a PC running Windows XP. (Click images to enlarge.)
Click the Next button to begin installing IIS. You may be prompted to insert your Windows CD during this process, so you'll want to keep it handy. Once you've finished installing IIS, you can make changes to your Web server configuration from the Windows control panel under Administrative Tools by selecting the Internet Information Services icon. The IIS management console looks like the image shown in Figure 2.
Figure 2: This is what the IIS Management Console looks like.
As this figure shows, the standard setup comes with a Default Web Site configuration that can be used immediately to create ASP applications. Using the default configuration, these documents would be stored in the folder C:Inetpubwwwroot. Any HTML or ASP files placed in that directory will immediately become available from any other computers that have network access to this computer. In this example, the pages would be accessed by navigating to http://mypc/ or using the PC's local IP address.
Now that we've examined the basics, we're ready to start building ASP's
My First ASP
ASP coding is accomplished using Visual Basic Scripting language (VBScript). As its name suggests, this language is a subset of the Visual Basic programming language. The VBScript code used is executed on the Web server, and only HTML tags are sent to the browser. This concept is similar to the iSeries in that the main processing occurs on the server, and only screen input and output are sent to the 5250 client. This VBScript code is embedded within HTML documents. Segments of ASP code are enclosed in "<%" and "%>" tags. Figure 3 contains the source for a simple ASP document.
Figure 3: This is the source for my_first.asp
You'll notice that the ASP source sits in the middle of other HTML tags. This code executes a simple FOR/NEXT loop to display the numbers 10 through 1 in descending order in the browser window. To execute this example, copy my_first.asp into the root Web folder, C:InetpubWWWRoot.
Figure 4 illustrates the output generated in the browser.
Figure 4: This is what my_first.asp displays in the Web browser.
To display this example on your computer, navigate to your local system by either its system name or its IP address followed by the name of the page. In the example above, the name of the computer containing the Web page is webserver. While this is a very basic example, it helps to illustrate the use of embedded ASP code.
ASP to iSeries
If you're an iSeries programmer, you're probably thinking, "What's the point?" Remember that our ASP page is driven by VBScript code. This means that ActiveX components can also be used within our ASP. This includes ActiveX Data Objects (ADO), which can be used to access data on the iSeries. So, using ASP, we can create a Web page that reads and writes data on the iSeries. Since ADO can also be used to call programs on the iSeries, we can also run a job on the iSeries from an ASP. Let's take a look at a simple example of how to read iSeries data from an ASP. Figure 5 contains the source for this example.
Figure 5: This ASP generates a Web page using iSeries data.
This page begins by defining our ADO connection object. This object allows us to define the type of database we are connecting to as well as additional parameters specific to that connection. In our case, we are using the Client Access ODBC driver. It's important to recognize that the value for the SYSTEM parameter shown here would have to be changed to reflect the IP address or system name for your iSeries, and the UID and PWD values would have to reflect a valid user ID and password for your iSeries.
Next, we create an ADO recordset object. This object is the means through which we can retrieve data from the database defined on the connection object. The rs.open statement defines the data to be retrieved using an SQL SELECT statement.
Now, we use the Response.Write method to send output to the client browser. This statement can be used to send simple text or HTML tags, which the browser will then interpret. The "
Then, we read through each record within our recordset and output the field values in the appropriate column. When all records have been read (that is, the value of rs.EOF is TRUE), the rs.Close and conn.Close statements are executed to free up the ADO resources used by the page.
When loaded into the C:Inetpubwwwroot folder on your PC, this page will appear as shown in Figure 6.
Figure 6: The output from our ASP is shown in a Web browser.
This page displays a list of all files in the library QSYS on the iSeries defined on the connection object. This data is retrieved from the SYSTABLES file in QSYS2 library on that iSeries.
Again, this is a simple example, but it gives you an idea of the power and ease-of-use of ASP. In just over 30 lines of ASP code, we've created an application in no time flat that can read and display data from your iSeries.
Only the Beginning
In this article, we've just scratched the surface of how powerful Active Server Pages are. It's amazing how easily you can create Web-enabled applications that use your iSeries database. I once created a complete application in a half a day using ASP that would've taken me a week of programming time in RPG.
For more details and examples of creating ASP applications that access the iSeries, check out my book Active Server Pages Primer. This book will help get you on the road to ASP ASAP.
Mike Faust is an application programmer for Fidelity Integrated Financial Solutions in Maitland, Florida. Mike is also the author of the books The iSeries and AS/400 Programmer's Guide to Cool Things, and Active Server Pages Primer, and SQL Built-in Functions and Stored Procedures. You can contact Mike at