Listing 17.1 illustrates a simple ASP file that you could create
in a folder on your Web server.
LISTING 17.1
AN ASP FILE
<HTML>
<BODY>
<B>ASP-generated section follows:</B><BR>
<%
‘GET THE CURRENT TIME AS A FORMATTED STRING
Dim sTime
sTime = Now
‘OUTPUT TIME INFORMATION IN HTML TEXT
Response.WritesTime
Response.Write "<BR>"
‘INITIALIZE ASP CLASS OBJECTS TO GET
‘INFORMATION ABOUT THE E: DRIVE
Dim objFileSys, objDrives, objDrive
On error Resume Next
Set objFileSys = _
Server.CreateObject("Scripting.FileSystemObject")
Set objDrives = objFileSys.Drives
Set objDrive = objDrives("F")
‘OUTPUT VOLUME INFORMATION IN HTML TEXT
Response.Write "The Volume Label In Drive <B>"
Response.Write objDrive.DriveLetter
Response.Write "</B> is <B>"
Response.Write objDrive.VolumeName
Response.Write "</B><BR>"
’CLEAN UP OBJECTS
Set objDrives = Nothing
Set objFileSys = Nothing
Set objDrive = Nothing
%>
<B>End of ASP-generated section</B>
</BODY>
</HTML>
Note the following features of an ASP file, as illustrated in
Listing 17.1:
-
Besides the enhanced ASP features, an ASP file also contains normal HTML script.
In the preceding listing example, note the beginning and ending <BODY> and
<HTML> tags, as well as the HTML text with bold formatting (<B>…</B>)
tags toward the beginning and end of the file. Any normal HTML script outside
the ASP delimiters (as discussed in the next point) will pass through to the end
user’s browser as-is.
-
The ASP-specific portions of the file are delimited by the <%…%>
pair of tags. Everything between this pair of tags is interpreted by ASP and then
gets stripped out before it reaches the end-user’s browser.
-
The ASP portion of the file is written in VBScript, which is basically a subset
of VB. You should recognize the VB syntax of the ASP code in the example.
-
Note the use of CreateObject, which allows the VBScript code to instantiate
COM objects from classes registered on the Web server machine. Chapter 10, "Instantiating
and Invoking a COM Component," discusses programming with existing COM components
in more detail. The capability to instantiate components inside an ASP script
is the key to launching WebClass applications, as discussed in the following sections.
-
ASP provides several built-in object classes not found in the VB environment.
The example uses two of these object classes, the Response object and the Scripting.FileSystemObject
class.
- In the ASP section of the file, you use the Response object’s Write
method to generate HTML code that will be embedded in the final HTML file that
the server sends to the browser. All arguments to the Response object are string
literals or variables, as shown in the example.
The sample ASP file of Listing 17.1 would produce an end result on client browsers
that would look like Figure 17.1.

FIGURE 17.1 How the ASP file appears on a browser
If end users chose the View Source option on the browser to see
the HTML code behind the page, they would see something very close to Listing
17.2
LISTING 17.2
INTERNET INFORMATION SERVER GENERATED THIS PURE HTML CODE FROM THE ASP FILE AND
SENT IT TO THE BROWSER
<HTML>
<BODY>
<B>ASP-generated section follows:</B><BR>
11/28/98 12:08:16 AM<BR>The Volume Label In Drive <B>F</B> is
<B>VSE600ENU2</B><BR>
<B>End of ASP-generated section</B>
</BODY>
</HTML>
Notice that Listing 17.2 shows no trace of the ASP code. Instead, it shows
only the basic HTML code that was in the file outside of the ASP section and the
output of the Response.Write method from the ASP section. The Web server stripped
out all the ASP code before transmitting the page to the browser.