Chapter 33 - Active Server Pages (ASP) : 2004 Prentice Hall, Inc. All Rights Reserved
Chapter 33 - Active Server Pages (ASP) : 2004 Prentice Hall, Inc. All Rights Reserved
Objectives
33.1 Introduction
• Server-side technologies
– Dynamically creates Web pages
• Use client information, server information and information
from the Internet
– Active Server Pages (ASP)
• Microsoft Server-side technology
• Dynamically build documents in response to client requests
– Deliver dynamic Web content
• XHTML, DHTML, ActiveX controls, client-side
scripts and Java applets
33.3 Setup
• Web Server
– Need to run Web server to use Active Server Pages
• IIS 5.0 (Internet Information Services) or higher
– Create a virtual directory
• Copy files to c:\InetPub\Wwwroot
• Built-in objects
– Communicate with a Web browser
– Gather data sent by HTTP request
– Distinguish between users
– Request
• Get or post information
• Data provided by the user in an XHTML form
• Access to information stored on client machine
– Cookies
– File upload (binary)
– Response
• Sends information to client
– XHTML, text
– Server
• Access to server methods or properties
• ASP Scripts
– Scripting delimiters
• <% %>
• @LANGUAGE directive
– Option Explicit
• As in VBScript, forces all variables to be declared in advance
– FormatDateTime
• Time to display
– Now
• Format to display in
Property Description
AvailableSpace Variant. The amount of available Drive space in bytes.
DriveLetter String. The letter assigned to the Drive (e.g., “C”).
DriveType Integer. The Drive type. Constants Unknown, Removable, Fixed,
Remote, CDRom and RamDisk represent Drive types and have the
values 0–5, respectively.
FileSystem String. The file system Drive description (FAT, FAT32, NTFS, etc.).
FreeSpace Variant. Same as AvailableSpace.
IsReady Boolean. Indicates whether or not a Drive is ready for use.
Path String. The Drive’s path.
RootFolder Folder object. The Drive’s root Folder.
SerialNumber Long. The Drive serial number.
TotalSize Variant. The total Drive size in bytes.
VolumeName String. The Drive volume name.
Fig. 33.10 Drive properties.
ReadLine String. Returns one line from the file referenced by the
TextStream object.
Write String. Writes text to the file referenced by the TextStream object.
• Creating a guestbook
– XHTML Form
– hidden field
• Determine if page loaded by form submission
– Write data to text file
• ServerVariables
• APPL_PHYSICAL_PATH
• OpenTextFile
• Append mode
–8
XHTML generated by
guestbook.asp
(1 of 1)
• ASP application
– Multiple ASP pages linked with session variables
– Example
• instantpage.asp
– Form, requests information from the user
– Posted to process.asp
• process.asp
– Redirects user to instantpage.asp if errors exist
– Otherwise creates users ASP page
– Stores message in session variable welcomeBack
• Every time user submits the form
• Server-side include
– Commands embedded in XHTML documents
– Add dynamic content
– Places a .shtml include file within another file
– Physical or virtual path
• <!--#include file = “includes\file.shtml” -->
– Not all Web servers support
• Written as comment
– Performed before scripting code is interpreted.
• ASP page cannot determine which includes to use
– Can contain scripting code
• Must use <script> tag or <% %> delimiters
• ADO
– Enables database connectivity
– Part of Universal Data Access architecture
• OLE DB provides low-level access
• ODBC allows C programs to access databases
• ADO allows web applications to access databases
– Provides pre-built objects for use in ASP and VBScript
• Collections
Application or Browser
ADO
OLE DB
ODBC
Connection
Errors Error