| the complete webmaster | ||||
| tutorials | reviews | reference | ||
|
Active Server Pages: An Introduction to Web-based Application DevelopmentWelcome. This article is the first of many in an ongoing series about developing web content using Microsofts Active Server Pages. It is intended for developers and webmasters who are new to Microsofts active content strategy including Internet Information Server (IIS), Active Server Pages (ASP), Active Data Objects (ADO) and the Component Object Model (COM) but are not necessarily new to the Windows NT Platform, Microsoft products or web development in general. This series will be produced bi-weekly to provide how-to information on building web applications from the ground up in the Active Server Pages environment. We will cover topics such as scripting, database access, component object development and application integration using the suite of tools provided in Microsoft Visual Studio 97 and Internet Information Server. If youve been building dynamic web sites using tools such as Perl, C, ISAPI or other technologies such as Microsofts Internet Database Connector or Allaires Cold Fusion, I urge you to read ahead to see whats possible using the latest server-side technology from Microsoft - Active Server Pages. An Introduction to the Active PlatformMicrosoft has a very 'active' perspective on how application architectures should be created. For that matter, the word 'active' or more specifically, the term ActiveX, has become a standard part of packaging just about every product concept released from Microsoft within the last year. Active Platform is the name given to Microsoft's component-based application development model for the Web. Active Platform is divided into three major sections:
Given that definition, let's turn our attention to where server-based applications are created. The Active Server Side of ThingsActive Server components actually constitute what we traditionally think of as the 'middle' tier, or business rule layer of an enterprise application. These components are responsible for encapsulating the majority of an application's transaction and database logic. For example, you might decide to place the logic for a complex calculation that requires access to several database tables inside an Active Server component. This component would then be invoked by other Active Server components during execution of one or more of your enterprise applications. The server-side execution environment that makes much of this possible is named Active Server Pages (formerly code-named "Denali"), an environment in Microsoft Internet Information Server that executes ActiveX Scripts and ActiveX Components on a server. Welcome to Active Server PagesActive Server Pages are a key component of Microsofts dynamic web content strategy. With Active Server Pages, a software developer can create interactive and personalized web pages for their World Wide Web site or corporate intranet without having to understand the internals of a web server or complex application programming interfaces. In addition, Active Server Pages is extensible via software components written using Microsofts Component Object Model so youll be able to take advantage of code youve already written using languages such as Visual Basic, C++ or Java. A Little History The World Wide Web came to life in 1990 when researchers at Switzerlands CERN laboratory needed to distribute documents and graphics via the Internet but needed something more than simple file transfers. Its a familiar story, but it was this series of events that led up to the creation of the most significant evolutionary period in application development. From Web Sites to Web Applications After the initial introduction of the web, a specification emerged: CGI, or the Common Gateway Interface. This specification allowed resources, in the form of executable programs, to be requested by a web browser and executed by a web server via a standard Uniform Resource Locator or URL. These CGI-based programs could take user input in the form of command line parameters and use the standard input and output file handles of a program to receive and generate HTML output in response to a browsers request. In addition, various pieces of state information located on the server could be interrogated by the program during execution and used to make logic decisions as to how this processing should occur. The ultimate goal: use this logic and processing capability to provide a custom experience for the user on the other side of the browser. In one way or another, what emerged was a means of using logic far beyond the capabilities of HTML to accomplish standard data processing functionality such as input validation and database access and the power to distribute that processing across the world. Where Active Server Pages Fit In Active Server Pages were introduced with release 3 of Microsofts web server, Internet Information Server or IIS. Active Server Pages are actually a series of dynamic link libraries or DLLs that are installed on your web server by either a standalone installation program or as part of the Visual Studio 97 setup for Visual InterDev. These DLLs give IIS the ability to interpret and process information via the use of a script file (called an ASP script) that is resident in your web application directory. Scripts and Why They Are DifferentOnce you complete the installation of Active Server Pages, a web browser can request scripts just as if it were requesting an HTML file. The difference is these files contain Active Server Page script, usually in the form of VBSCRIPT or JSCRIPT, and have a file extension of .ASP. When requested, these scripts execute in the Active Server Page environment instead of being simply returned to the browser and produce output for sending back to the requesting browser. You may be wondering just how quickly, if at all, you or your web developers could take advantage of this technology. For starters, lets take a look at how you get your Active Server Pages environment up and running. Then well build our first script that dynamically generates an HTML page. Installing the Active Server Pages Environment In Windows NT Whether your platform is Windows NT Server 4.0, Windows NT Workstation 4.0 or Windows 95, you will need to first install and start a web server that is compatible with the Active Server Pages environment. To date, each of these platforms provide a web server that supports Active Server pages. For Windows NT Server there is Microsofts Internet Information Server, for Windows NT Workstation theres Microsofts Peer Web Services, and for Windows 95, theres Personal Web Server. If youve ever installed Windows NT Server 4.0, you have probably been asked if you want to install Internet Information Server. Answering Yes to this question will install the default configuration for Internet Information Server version 2.0. Then, youll need to install NT Service Pack 3. This will upgrade your current IIS 2.0 installation to 3.0, the necessary release for Active Server Pages. After installing IIS 3.0, youll need to install Active Server Pages. Youll find this installation either on the Microsoft Web download page, NT Service Pack 3, or as part of your Visual Studio 97 installation. Now youre ready to write your first script: Active Server Pages 101 The following script can be written using a text editor such as the Windows NotePad. Its' intent is to display four lines of text in the browser window that say "Hello ASP World!" each in a larger font:
Notice there is a mixture of what appears to be HTML and BASIC. The BASIC is actually VBSCRIPT and the HTML is, you guessed it, plain vanilla HTML. Lets take a quick tour of this example and see what its made up of and what it produces as its final output in the browser. HELLO.ASP includes three standard HTML elements: HEAD, TITLE and BODY. For all intents and purposes, this is the proposed HTML page to be sent to the requesting browser when the HELLO.ASP page executes. If you look closely, youll see several occurrences of "<%" and "%>". These angle-bracket percent signs are the opening and closing tags for a block of ASP script. You should note that ASP is not really a script, its actually a host environment for any number scripting languages such as VBSCRIPT, JSCRIPT and others including even a third-party Active Server Page version of PerlScript. A Dissection of HELLO.ASPThe first line of HELLO.ASP is actually a special scripting tag that tells the ASP interpreter to set the default scripting language to VBSCRIPT. As discussed earlier, the target language could have very well been JSCRIPT. The only condition is that the language in question must be registered as a valid scripting language in the servers registry. <%@ LANGUAGE="VBSCRIPT" %> The next five or so lines are HTML. We set a title then we open the BODY section of the document. <HTML> The next three lines make up the substance of our ASP script. If you are familiar with the BASIC language, youll immediately recognize the for-next looping construct in the code sample below. For those of you who are not, for-next is a BASIC language construct that allows a block of code to execute for a number of times. In this example, x is a variable that initially has a value of three and is incremented until, or to, the number 6 in other words we execute the code between the for and the next four times. <% for x = 3 to 6 %> The only thing left to explain is the <% =x %> occurring on the right of the SIZE= attribute of the FONT tag. This notation indicates that the contents of a variable named x will be substituted (which in this case will be 3, 4, 5 or 6) into the line prior to sending the HTML back to the browser.Whats actually generated and sent back to the requesting browser, is pure HTML that looks like this: <HTML><HEAD> <TITLE>My First ASP Script!</TITLE> </HEAD> <BODY> <FONT SIZE=3>Hello ASP World!</FONT><BR> <FONT SIZE=4>Hello ASP World!</FONT><BR> <FONT SIZE=5>Hello ASP World!</FONT><BR> <FONT SIZE=6>Hello ASP World!</FONT><BR> </BODY> </HTML> And whats rendered in the browsers document window looks like this: Hello ASP World! In Conclusion What youve just seen is an introductory example of producing dynamic web content with Microsofts Active Server Pages. No doubt, in the preceding code we could have done a few extra things to interact more with the environment. For example, we could have solicited some of the information used to produce this page from the user such as the beginning and ending font sizes (i.e. the initial and maximum values for the for-next loop). We'll see how this is possible a little later on. However, from this article you should remember several key concepts:
Over the next several articles, well be investigating some of the more advanced steps youll take to activate your web site. You'll learn about intrinsic objects available to you when writing Active Server Page scripts then you'll see how to create COM components and fully integrate them into your web application. Eventually, we'll integrate Active Data Objects and HTML forms to produce a full-featured data-entry application. For some additional reading, you might want to try "Professional Active Server Pages" published by Wrox Press. I'll make other reading suggestions available to you as we proceed throughout our discussions. See you next time!
Author: Keith Cox More articles about Active Server Pages |
| write for us | about us | advertise |
Copyright 1997, 1998 A Big Lime. All rights reserved.