Creating Active Server Pages


Introduction.  Remember, ASP pages are composed of programmatic code and embedded HTML.  There really is nothing mysterious about them.  Well, nothing mysterious to relatively experienced software developers.  They are text files and can be created in Notepad, FrontPage or InterDev.  When the ASP page is requested by a user it's programmatic code is executed by the host/remote server and then downloaded to the user as HTML code. The programmatic code is delimited differently from typical HTML.

ASP is a server technology not a computer language.  VBScript, JavaScript, PerlScript and Python are four of the most typical scripting languages used to create the programmatic code in ASPs.

While there are several ways to implement ASPs, we will start with the following.  Lines that are included between an


and a


are treated as script that should be compiled and executed by the host server. 

You also want to make certain your file has a .asp extension.

The results of this are then placed into HTML so that user can see or interact with the resulting page.

The scripting language that should be used is determined by the very first line in the file.

<%@ Language=VBScript %>

signals the server to start looking for VBScript source code.

As with any topic, there are a huge variety of things we could cover.  If you want a good reference that goes into more depth on ASPs you should consider the Mitchell and Atkinson book listed on the course page.  In this course, we are going to spend about four weeks focusing on ASPs in order to get you up to a level where you can develop e-commerce webs as done in Jerke.

Your First ASP.  Well, this is your first ASP in this course anyway.  I am about to develop a relatively straightforward ASP which you should copy.  We will then dissect it during class.  The ASP will find the cube of the first ten digits.  As advertised, it is a mixture of VBScript and HTML.

At this point you should just copy the code into some sort of text editor and save it as Cubes.asp in some sub-directory of the course directory you have created on your computer.

<%@ Language=VBScript %>
<% Option Explicit %>

<title>Calculating Cubes</title>


Dim iLoop 
For iLoop = 1 to 10
Response.Write "The cube of " & iLoop & " is " & iLoop*iLoop*iLoop & "<br>"



The code should be another indication that you have not wasted your time learning VB in the past.  

  • The first line tells the server you are going to try to write some VBScript code in the page.  

  • The Option Explicit requires you to dimension your variables at the beginning of a VBScript program.  It is VERY good programming practice to declare/dimension your variables up front for many reasons.

  • The <html> tag tells the server you are starting your HTML.  I will be lazy and use lower case letters for HTML, though it probably is slightly better to capitalize the tags to help them stand out.

  • The <head>, </head> pair of tags creates the page header including the title that will appear in the browser top bar when your page is used.

  • The <body>, </body> pair of tags delimit the body of the page.

  • The <B>Cubes</B><BR> will print Cubes in bold at the top of the page that the user sees and then put in a line break.

  • Now we get the VBScript code.  First the iLoop counter is dimensioned.

  • Then a For ... Next loop is set up to run the counter from 1 to 10.

  • The Response.Write command takes the stuff from VBScript and puts it back into the page as HTML.  The & append each "phrase" onto the preceding parts.  Notice that a line break is put in after each Response.Write is executed to the web page.

  • Then everything is closed out with the appropriate end tags.

Now you should FTP/publish this code to your root web for this course.  This will be a first test of whether your permissions are set up correctly.

After this you need to open your web browser of choice and go to the following URL.

at which point you should see the following image.



Notice the Calculating Cubes title for the browser and the Cubes title on the page.

This exercise should also server the purpose of making sure that your accounts, computers and software are working at least to this level.

The Process for ASP Enactment.  The following diagram represents the major steps in enacting and ASP.



The major steps involved are
  • Request - The user sends a message via the browser to the host server for a particular page
  • Preprocessing - The ASP.dll file does some initial processing
  • Execution - The scripting engine executes the script
  • Translation - The ASP.dll translates the results of the execution into HTML
  • Display - The HTML is sent back to the user via the browser whcih processes the HTML tags and displays the page.

It is important to remember that this ASP enactment process is completed when the page is sent back to the user.  Other enactments may be requested, but this is the nature of server-side processing.