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.