19
Fri, Apr
5 New Articles

Living the Active (Server Pages) Lifestyle?

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times


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.

The Setup

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.)

http://www.mcpressonline.com/articles/images/2002/aspV4--11070500.jpg
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.

http://www.mcpressonline.com/articles/images/2002/aspV4--11070501.png
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.



Countdown

<%
For X = 10 to 1 Step -1
Response.Write(X & "
")

Next
Response.Write("Blastoff!!!")
%>

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.

http://www.mcpressonline.com/articles/images/2002/aspV4--11070502.png
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.

"
For x = 0 to rs.fields.count - 1
Response.Write ""
Next
Response.Write ""

Do Until rs.EOF
Response.Write ""
For x = 0 to rs.fields.count - 1
Response.Write ""
Next
Response.Write ""
rs.MoveNext
Loop
rs.Close
conn.Close
%>
File Listing


<%
Set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DRIVER=Client Access ODBC Driver (32-bit);REMARKS = 1;" & _ 
  "LIBVIEW = 1;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID = ENU;" & _ 
  "DFTPKGLIB = QGPL;SYSTEM = 192.168.0.1; UID = user; PWD = secret "

Set rs=Server.CreateObject("ADODB.Recordset")

rs.Open "SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TEXT " & _ 
"FROM QSYS2.SYSTABLES WHERE TABLE_SCHEMA='QSYS'", conn
Response.Write "
" & rs.Fields(x).Name & "
" & rs.Fields(x) & "


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 "" tag is used to define a row within a table. After that, a FOR/NEXT loop is used to output the field names for each row in our recordset object. These values are used as column headings within our table.

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.

http://www.mcpressonline.com/articles/images/2002/aspV4--11070503.jpg
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 This email address is being protected from spambots. You need JavaScript enabled to view it..

Mike Faust

Mike Faust is a senior consultant/analyst for Retail Technologies Corporation in Orlando, Florida. Mike is also the author of the books Active Server Pages Primer, The iSeries and AS/400 Programmer's Guide to Cool Things, JavaScript for the Business Developer, and SQL Built-in Functions and Stored Procedures. You can contact Mike at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Mike Faust available now on the MC Press Bookstore.

Active Server Pages Primer Active Server Pages Primer
Learn how to make the most of ASP while creating a fully functional ASP "shopping cart" application.
List Price $79.00

Now On Sale

JavaScript for the Business Developer JavaScript for the Business Developer
Learn how JavaScript can help you create dynamic business applications with Web browser interfaces.
List Price $44.95

Now On Sale

SQL Built-in Functions and Stored Procedures SQL Built-in Functions and Stored Procedures
Unleash the full power of SQL with these highly useful tools.
List Price $49.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: