7/31/2019 Csc 318 - Lecture 12-1 - ASP
1/102
2004 Prentice Hall, Inc. All rights reserved.
1
Active Server Pages (ASP) Outline33.1 Introduction33.2 How Active Server Pages Work33.3 Setup33.4 Active Server Page Objects33.5 Simple ASP Examples33.6 File System Objects33.7 Session Tracking and Cookies33.8 ActiveX Data Objects (ADO)33.9 Accessing a Database from an Active Server Page33.10 Server-Side ActiveX Components33.11 Web Resources
7/31/2019 Csc 318 - Lecture 12-1 - ASP
2/102
2004 Prentice Hall, Inc. All rights reserved.
2
Objectives
In this tutorial, you will learn: To program Active Server Pages using VBScript. To understand how Active Server Pages work. To understand the differences between client-side scripting
and server-side scripting. To be able to pass data between Web pages. To be able to use server-side include statements. To be able to use server-side ActiveX components.
To be able to create sessions. To be able to use cookies. To be able to use ActiveX Data Objects (ADO) to access a
database.
7/31/2019 Csc 318 - Lecture 12-1 - ASP
3/102
2004 Prentice Hall, Inc. All rights reserved.
3
33.1 Introduction
Server-side technologies Dynamically creates Web pages
Use client information, server information and informationfrom 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
7/31/2019 Csc 318 - Lecture 12-1 - ASP
4/102
2004 Prentice Hall, Inc. All rights reserved.
4
33.2 How Active Server Pages Work
Active Server Pages Processed by scripting engine
Server-side ActiveX control .asp file extension
Can contain XHTML tags Scripting written with VBScript
JavaScript also used Others (Independent Software Vendors)
Communication with Server Client HTTP request to server Active server page processes request and returns results
7/31/2019 Csc 318 - Lecture 12-1 - ASP
5/102
2004 Prentice Hall, Inc. All rights reserved.
5
33.2 How Active Server Pages Work
Active Server Pages,cont. Communication with Server, cont.
ASP document is loaded into memory asp.dll scripting engine on server
Parses (top to bottom)
7/31/2019 Csc 318 - Lecture 12-1 - ASP
6/102
2004 Prentice Hall, Inc. All rights reserved.
6
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 toc:\InetPub\Wwwroot
7/31/2019 Csc 318 - Lecture 12-1 - ASP
7/1022004 Prentice Hall, Inc. All rights reserved.
7
33.4 Active Server Page Objects
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
7/31/2019 Csc 318 - Lecture 12-1 - ASP
8/1022004 Prentice Hall, Inc. All rights reserved.
8
33.4 Active Server Page Objects
Object Name DescriptionRequest Used to access information passed by an HTTP request.
Response Used to control the information sent to the client.Server Used to access methods and properties on the server.
Fig. 25.1 Commonly used ASP objects.
7/31/2019 Csc 318 - Lecture 12-1 - ASP
9/1022004 Prentice Hall, Inc. All rights reserved.
9
33.5 Simple ASP Examples
ASP Scripts Scripting delimiters
@LANGUAGEdirective
Option Explicit As in VBScript, forces all variables to be declared in advance
FormatDateTime Time to display
Now Format to display in
1
7/31/2019 Csc 318 - Lecture 12-1 - ASP
10/102
2004 Prentice Hall, Inc.All rights reserved.
Outline101
2
3
4
5
6
7
8
9
10
11
12
13
1415
16
17
18
19
20
21
22
23
24
25
clock.asp(1 of 2)
Scripting delimiterwraps around codeexecuted on the server.
Processing directivespecifying scriptinglanguageRequires programmer
explicitly define all variables
26
7/31/2019 Csc 318 - Lecture 12-1 - ASP
11/102
2004 Prentice Hall, Inc.All rights reserved.
Outline1126
27
28
29
30
31
32
33
34
35
36
37
38
3940
41
42
43
clock.asp(2 of 2)
Returns server date and time(Now) as a string formatted invbLongDate format
7/31/2019 Csc 318 - Lecture 12-1 - ASP
12/1022004 Prentice Hall, Inc. All rights reserved.
12
33.5 Simple ASP ExamplesFig. 33.2 Simple Active Server Page.
1
7/31/2019 Csc 318 - Lecture 12-1 - ASP
13/102
2004 Prentice Hall, Inc.All rights reserved.
Outline13
HTML generated by clock.asp(1 of 2)
1
2
3
4
5
6
7
8
9
10
11
12
13
1415
16
17
18
19
20
21
7/31/2019 Csc 318 - Lecture 12-1 - ASP
14/102
2004 Prentice Hall, Inc.All rights reserved.
Outline14
HTML generated by clock.asp(2 of 2)
21
22
23
24
25
26
27
28
29
30
31
32
33
3435
7/31/2019 Csc 318 - Lecture 12-1 - ASP
15/1022004 Prentice Hall, Inc. All rights reserved.
15
33.5 Simple ASP Examples
ASP processes input Form information sent by client E-commerce Web site
Use to verify customer information
Server responds to process request Form
Using post method action attribute indicates the .asp file to which the form
information is posted Request object retrieves form data
1
7/31/2019 Csc 318 - Lecture 12-1 - ASP
16/102
2004 Prentice Hall, Inc.All rights reserved.
Outline161
2
3
4
5
6
7
8
9
10
11
12
13
1415
16
17
18
name.html(1 of 2)
19
7/31/2019 Csc 318 - Lecture 12-1 - ASP
17/102
2004 Prentice Hall, Inc.All rights reserved.
Outline1719
20
21
22
23
24
25
26
27
28
action set to ASP filewhere information ispost ed.
name.html(2 of 2)
18
7/31/2019 Csc 318 - Lecture 12-1 - ASP
18/1022004 Prentice Hall, Inc. All rights reserved.
18
33.5 Simple ASP ExamplesFig. 33.4 XHTML document that requests an ASP.
191
7/31/2019 Csc 318 - Lecture 12-1 - ASP
19/102
2004 Prentice Hall, Inc.All rights reserved.
Outline191
2
3
4
5
6
7
8
9
10
11
12
13
1415
16
17
18
19
20
21
22
name.asp(1 of 2)
2023
7/31/2019 Csc 318 - Lecture 12-1 - ASP
20/102
2004 Prentice Hall, Inc.All rights reserved.
Outline2023
24
25
26
27
28
29
30
31
32
name.asp(2 of 2) Request object retrieves
form data from text fieldnamebox
21
7/31/2019 Csc 318 - Lecture 12-1 - ASP
21/1022004 Prentice Hall, Inc. All rights reserved.
21
33.5 Simple ASP ExamplesFig. 33.5 ASP document that responds to a client request.
22
7/31/2019 Csc 318 - Lecture 12-1 - ASP
22/1022004 Prentice Hall, Inc. All rights reserved.
22
33.6 File System Objects
File System Objects (FSOs) Allow programmer to manipulate files, directories and drives Read and write text Microsoft Scripting Runtime Library (Fig 33.6)
FileSystemObject , File , Folder , Drive andTextStream
Use to create directories, move files, determine whether aDrive exists
FileSystemObject methods (Fig. 33.7)
File object Allows programmer to gather info about files, manipulate files,
open files File properties and methods (Fig. 33.8)
23
7/31/2019 Csc 318 - Lecture 12-1 - ASP
23/1022004 Prentice Hall, Inc. All rights reserved.
23
33.6 File System Objects
Object type DescriptionFileSystemObject Allows the programmer to interact with File s, Folder s and
Drive s.File Allows the programmer to manipulate File s of any type.Folder Allows the programmer to manipulate Folder s (i.e., directories).Drive Allows the programmer to gather information about Drive s (hard
disks, RAM disks computer memory used as a substitute for harddisks to allow high-speed file operations, CD-ROMs, etc.). Drive scan be local or remote.
TextStream Allows the programmer to read and write text files.
Fig. 33.6 File System Objects (FSOs).
24
7/31/2019 Csc 318 - Lecture 12-1 - ASP
24/102
2004 Prentice Hall, Inc. All rights reserved.
24
33.6 File System Objects
Methods DescriptionCopyFile
Copies an existing File .CopyFolder Copies an existing Folder .CreateFolder Creates and returns a Folder .CreateTextFile Creates and returns a text File .DeleteFile Deletes a File .DeleteFolder Deletes a Folder .DriveExists Tests whether or not a Drive exists. Returns a boolean.FileExists Tests whether or not a File exists. Returns a boolean.FolderExists Tests whether or not a Folder exists. Returns a boolean.GetAbsolutePathName Returns the absolute path as a string.Fig. 33.7 FileSystemObject methods. (Part 1 of 2)
25
7/31/2019 Csc 318 - Lecture 12-1 - ASP
25/102
2004 Prentice Hall, Inc. All rights reserved.
25
33.6 File System Objects
Methods DescriptionGetDrive
Returns the specified Drive .GetDriveName Returns the Drive drive name.GetFile Returns the specified File .GetFileName Returns the File file name.GetFolder Returns the specified File .GetParentFolderName Returns a string representing the parent folder name.
GetTempName Creates and returns a string representing a file name.MoveFile Moves a File .MoveFolder Moves a Folder .OpenTextFile Opens an existing text File . Returns a TextStream .Fig. 33.7 FileSystemObject methods. (Part 2 of 2)
26
7/31/2019 Csc 318 - Lecture 12-1 - ASP
26/102
2004 Prentice Hall, Inc. All rights reserved.
26
33.6 File System ObjectsProperty/method Description
Property
DateCreated Date. The date the File was created.DateLastAccessed Date. The date the File was last accessed.DateLastModified Date. The date the File was last modified.Drive Drive . The Drive where the file is located.
Name String. The File name.ParentFolder String. The File s parent folder name. Path String. The File s path. ShortName String. The File s name expressed as a short name. Size Variant. The size of the File in bytes.
Method Copy Copy the File . Same as CopyFile of FileSystemObject .Delete Delete the File . Same as DeleteFile of FileSystemObject .Move Move the File . Same as MoveFile of FileSystemObject .OpenAsTextStream Opens an existing File as a text File . Returns TextStream .
Fig. 33.8 Some common File properties and methods.
27
7/31/2019 Csc 318 - Lecture 12-1 - ASP
27/102
2004 Prentice Hall, Inc. All rights reserved.
27
33.6 File System Objects
File System Objects (FSOs) Path property Contains File path in long name format
ShortName property Contains File path in short name format
Folder object Allows programmer to manipulate and gather info about
directories Folder properties (Fig. 33.9)
28
7/31/2019 Csc 318 - Lecture 12-1 - ASP
28/102
2004 Prentice Hall, Inc. All rights reserved.
28
33.6 File System ObjectsPrope rty/ me thod Description
Properties
Attributes Integer. Value indicating Folder s attributes (read only, hidden, etc.). DateCreated Date. The date the folder was created.DateLastAccessed Date. The date the folder was last accessed.DateLastModified Date. The date the folder was last modified.Drive Drive . The Drive where the folder is located.
IsRootFolder Boolean. Indicates whether or not a Folder is a root folder.Name String. The Folder s name. ParentFolder Folder . The Folder s parent folde r.Path String. The Folder s path. ShortName String. The Folder s name expressed as a short name. ShortPath String. The Folder s path expressed as a short path. Size Variant. The total size in bytes of all subfolders and files.
Type String. The Folder type.Fig. 33.9 Some Folder properties and methods. (Part 1 of 2)
29
7/31/2019 Csc 318 - Lecture 12-1 - ASP
29/102
2004 Prentice Hall, Inc. All rights reserved.
29
33.6 File System Objects
Property/method Description
MethodsDelete Delete the Folder . Same as DeleteFolder of
FileSystemObject .Move Move the Folder . Same as MoveFolder of
FileSystemObject .Copy Copy the Folder . Same as CopyFolder of
FileSystemObject .Fig. 33.9 Some Folder properties and methods. (Part 2 of 2)
30
7/31/2019 Csc 318 - Lecture 12-1 - ASP
30/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
File System Objects (FSOs) IsRootFolder property Indicates whether folder is the root folder for the Drive If not:
Method ParentFolder
Retrieves parent folder Method Size
Returns the total bytes the folder contains (includessubfolders)
31
7/31/2019 Csc 318 - Lecture 12-1 - ASP
31/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
File System Objects (FSOs) Drive object (Fig. 33.10) Gather information about drives Property DriveLetter
Contains drive letter Property SerialNumber
Contains drive serial number Property FreeSpace
Contains number of available bytes
32
7/31/2019 Csc 318 - Lecture 12-1 - ASP
32/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
Property DescriptionAvailableSpace 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 , CDRomand RamDisk represent Drive types and have thevalues 0 5, respectively.
FileSystemString. 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.
33
7/31/2019 Csc 318 - Lecture 12-1 - ASP
33/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
File System Objects (FSOs) TextStream object (Fig. 33.11) Manipulate text files
34
7/31/2019 Csc 318 - Lecture 12-1 - ASP
34/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
Prope rty/ Me thod Description
PropertiesAtEndOfLine Boolean. Indicates whether the end of a line has been encountered.AtEndOfStream Boolean. Indicates whether the end of file has been encountered.Column Integer. Returns the characters position in a line.Line Integer. Returns the current line number.
MethodsRead String. Returns a specified number of characters from the file
referenced by the TextStream object.ReadAll String. Returns the entire contents of the file referenced by the
TextStream object.Fig. 33.11 TextStream methods and properties. (Part 1 of 2)
35
7/31/2019 Csc 318 - Lecture 12-1 - ASP
35/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
Prope rty/ Me thod Description
Methods, cont.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.
WriteBlankLines String. Writes newline characters to the file referenced by the
TextStream object.WriteLine String. Writes one line to the file referenced by the TextStream
object.Skip Variant. Skips a specified number of characters while reading from the
file referenced by the TextStream object.SkipLine Variant. Skips a line of characters while reading from the file
referenced by the TextStream object.Close Close the file referenced by the TextStream object.
Fig. 33.11 TextStream methods and properties. (Part 2 of 2)
36
7/31/2019 Csc 318 - Lecture 12-1 - ASP
36/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
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
37
7/31/2019 Csc 318 - Lecture 12-1 - ASP
37/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
Creating a guestbook, cont. Name returned as mailto: URL Request object
Chr function Generate characters from ASCII code
Always Close files
O li381
2
7/31/2019 Csc 318 - Lecture 12-1 - ASP
38/102
2004 Prentice Hall, Inc.All rights reserved.
Outline23
4
5
6
7
8
9
10
11
12
13
1415
16
17
18
19
20
2122
23
24
guestbook.asp(1 of 5)
O li3925
26
7/31/2019 Csc 318 - Lecture 12-1 - ASP
39/102
2004 Prentice Hall, Inc.All rights reserved.
Outline2627
28
29
30
31
32
33
34
35
36
37
3839
40
41
42
43
44
4546
47
48
49
guestbook.asp(2 of 5)
Concatenated with filename guestbook.txt
Creating a FSO instance
assigned to reference fileObject
Set is required to establish avariable in VBScript
Request object retrieveshiddenInput value and testsit against string true Prints string followed by
users name input in the form
Date() assigns currentserver date to beginning of mailtoUrl
Displays a mailto : link.
Submitted name and emailare combined and assigned tostring mailtoUrlPass value 34 into VBScript
Chr function to produce doublequotes ( )
Request retrieves email andusername
Pass Request methodServerVariables server keyAPPL_PHYSICAL_PATH
O li4050
51
7/31/2019 Csc 318 - Lecture 12-1 - ASP
40/102
2004 Prentice Hall, Inc.All rights reserved.
Outline5152
53
54
55
56
57
58
59
60
61
62
6364
65
66
67
68
69
7071
72
73
74
guestbook.asp(3 of 5)
Method OpenTextFile retrieves TextStream objectfor accessing fileguestbook.txt
Contstant 8 indicatesappend mode (writing tothe end of the file.)
TextStream methodWriteLine writes to guestbook.txt
Close() method closes the file
Form post action to .asp page
O tli4175
76
7/31/2019 Csc 318 - Lecture 12-1 - ASP
41/102
2004 Prentice Hall, Inc.All rights reserved.
Outline
guestbook.asp(4 of 5)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
9596
97
98
99
Form contains twotext fields and textarea for user input
Passes parameterhiddenInput value true
O tli42100
101
7/31/2019 Csc 318 - Lecture 12-1 - ASP
42/102
2004 Prentice Hall, Inc.All rights reserved.
Outline101102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
guestbook.asp(5 of 5)
FSO object FileExists checks if guestbook.txt exists.
Read entries fromguestbook.txt and writeXHTML to the client
TextStream and ReadAll methods read entirecontents of guestbook.txt
Response.Write writestext to client. ContainsXHTML markup renderedon client browser.
43
7/31/2019 Csc 318 - Lecture 12-1 - ASP
43/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System ObjectsFig. 33.12 Guestbook Active Server Page.
44
7/31/2019 Csc 318 - Lecture 12-1 - ASP
44/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System ObjectsFig. 33.12 Guestbook Active Server Page.
Outline451
7/31/2019 Csc 318 - Lecture 12-1 - ASP
45/102
2004 Prentice Hall, Inc.All rights reserved.
Outline
XHTML generated by guestbook.asp(1 of 1)
2
46
7/31/2019 Csc 318 - Lecture 12-1 - ASP
46/102
2004 Prentice Hall, Inc. All rights reserved.
33.6 File System Objects
Key name DescriptionAPPL_PHYSICAL_PATH Returns the physical path.HTTPS Boolean. Determines whether the request
came in through SSL (Secure Sockets Layer).REMOTE_ADDR Clients DNS name or IP addres s.REQUEST_METHOD Request method (i.e., get and post).SERVER_NAME Servers hostname (DNS or IP address).
HTTP_USER_AGENT Returns information about the client makingthe request.HTTP_COOKIE Returns cookies residing on the client.Fig. 33.13 Some server variable keys.
47
7/31/2019 Csc 318 - Lecture 12-1 - ASP
47/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and Cookies
Session Tracking and Cookies Helps server to distinguish between clients Provide custom content
Shopping cart Marketing/advertising
SessionID Assigned by server to each unique session Compared with sessionID s stored in server
Session object Timeout property
Length of session before it expires Abandon property
Terminates individual session
48
7/31/2019 Csc 318 - Lecture 12-1 - ASP
48/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and Cookies
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
49
7/31/2019 Csc 318 - Lecture 12-1 - ASP
49/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and Cookies
Server-side include Commands embedded in XHTML documents Add dynamic content Places a .shtml include file within another file Physical or virtual path
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 tag or delimiters
Outline501
2
7/31/2019 Csc 318 - Lecture 12-1 - ASP
50/102
2004 Prentice Hall, Inc.All rights reserved.
Outline3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2122
23
24
25
instantpage.asp(1 of 4)
Outline5126
27 Server-side include
7/31/2019 Csc 318 - Lecture 12-1 - ASP
51/102
2004 Prentice Hall, Inc.All rights reserved.
Outline28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
4647
48
instantpage.asp(2 of 4)
Server-side include
errorMessage sessionvariable used for errormessages welcomeBack session
variable displayswelcome back messageto returning users
If statement testserrorMessage equalityto no error . ReturnTrue or False .
If true, errorMessage value is written to client
Else, WelcomeBack value iswritten to the client
First time page is executed,
line 35 returns true
errorMessage never has avalue unless errors areencountered
Session object
retrieves variable value
Requests process.asp whenform is posted
Outline5249
50
7/31/2019 Csc 318 - Lecture 12-1 - ASP
52/102
2004 Prentice Hall, Inc.All rights reserved.
Outline51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
6970
71
72
instantpage.asp(3 of 4)
Outline5373
74
7/31/2019 Csc 318 - Lecture 12-1 - ASP
53/102
2004 Prentice Hall, Inc.All rights reserved.
Outline75
76
77
78
79
80
81
82
83
84
85
instantpage.asp(4 of 4)
Server-side include
54
7/31/2019 Csc 318 - Lecture 12-1 - ASP
54/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and CookiesFig. 33.15 ASP that posts user information to process.asp.
55
7/31/2019 Csc 318 - Lecture 12-1 - ASP
55/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and CookiesFig. 33.15 ASP that posts user information to process.asp.
56
7/31/2019 Csc 318 - Lecture 12-1 - ASP
56/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and CookiesFig. 33.15 ASP that posts user information to process.asp.
Outline571
2
7/31/2019 Csc 318 - Lecture 12-1 - ASP
57/102
2004 Prentice Hall, Inc.All rights reserved.
header.shtml(1 of 1)
3
4
5
Outline581
2
7/31/2019 Csc 318 - Lecture 12-1 - ASP
58/102
2004 Prentice Hall, Inc.All rights reserved.
footer.shtml
server-side include file
for the document footer
3
4
5
6
7
8
Outline591
2
7/31/2019 Csc 318 - Lecture 12-1 - ASP
59/102
2004 Prentice Hall, Inc.All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2122
23
24
25
process.asp(1 of 6)
If statement validatescontents of text field.
If field is empty orcontains default stringyourfilename , lines 19-21 assign XHTML errormessage to variablemessage.
Assign message value tosession variableerrorMessage
Server methodTransfer requestsinstantpage.asp
Outline6026
27
FSO object is created if valid user
R t S V i bl
7/31/2019 Csc 318 - Lecture 12-1 - ASP
60/102
2004 Prentice Hall, Inc.All rights reserved.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
4647
process.asp(2 of 6)
name is entered and assignedreference fileObject
Specify server path whereASP file is written
Request.ServerVariables retrieves physical path Builds fileName by
concatenatingfilename to the .aspfile extension
filePath passed FileExists method. Determines if file exists.
If file exists, variableerrorMessage value is set toXHTML containing error message
Server.Transfer methodrequests instantpage.asp
Outline6148
49
7/31/2019 Csc 318 - Lecture 12-1 - ASP
61/102
2004 Prentice Hall, Inc.All rights reserved.
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
6869
70
71
72
73
process.asp(3 of 6)
Assigns XHTML for welcome back message to welcomeBack session variableAssign ASP scripting
delimiters to string variablesopenMark and closeMark
Construct XHTML for header
Outline6274
75
7/31/2019 Csc 318 - Lecture 12-1 - ASP
62/102
2004 Prentice Hall, Inc.All rights reserved.
process.asp(4 of 6)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Form values retrievedusing Request object
footer variable assigned
to XHTML footer contents
Outline6394
95
7/31/2019 Csc 318 - Lecture 12-1 - ASP
63/102
2004 Prentice Hall, Inc.All rights reserved.
process.asp(5 of 6)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114115
116
117
118
Lines 103-129 send XHTML toclient that contains link to
created page
Outline64119
120
121
7/31/2019 Csc 318 - Lecture 12-1 - ASP
64/102
2004 Prentice Hall, Inc.All rights reserved.
process.asp(6 of 6)
121
122
123
124
125
126
127
128
129
Outline651
2
3
7/31/2019 Csc 318 - Lecture 12-1 - ASP
65/102
2004 Prentice Hall, Inc.All rights reserved.
aboutme.asp(1 of 2)
3
4
5
6
7
89
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Outline6626
27
28
7/31/2019 Csc 318 - Lecture 12-1 - ASP
66/102
2004 Prentice Hall, Inc.All rights reserved.
aboutme.asp(2 of 2)
28
29
30
31
32
3334
67
33 7 S i T ki d C ki
7/31/2019 Csc 318 - Lecture 12-1 - ASP
67/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and CookiesFig. 33.20 Welcome back message displayed by instantpage.asp .
68
33 7 S i T ki d C ki
7/31/2019 Csc 318 - Lecture 12-1 - ASP
68/102
2004 Prentice Hall, Inc. All rights reserved.
33.7 Session Tracking and CookiesFig. 33.21 Error message generated by instantpage.asp .
69
33 8 A ti X D t Obj t (ADO)
7/31/2019 Csc 318 - Lecture 12-1 - ASP
69/102
2004 Prentice Hall, Inc. All rights reserved.
33.8 ActiveX Data Objects (ADO)
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
70
33 8 A ti X D t Obj t (ADO)
7/31/2019 Csc 318 - Lecture 12-1 - ASP
70/102
2004 Prentice Hall, Inc. All rights reserved.
33.8 ActiveX Data Objects (ADO)
ADO
OLE DB
Legacy data Relational data sources
Application or Browser
Non-relational data sources
ODBC
Fig. 33.22 Microsofts UDA architecture.
71
33 8 A ti X D t Obj t (ADO)
7/31/2019 Csc 318 - Lecture 12-1 - ASP
71/102
2004 Prentice Hall, Inc. All rights reserved.
33.8 ActiveX Data Objects (ADO)Fig. 33.23 Portion of the ADO object model.
Field
Parameter
Fields
Error
Parameters
RecordSet
Errors
Command
Connection
72
33 8 A ti X D t Obj t (ADO)
7/31/2019 Csc 318 - Lecture 12-1 - ASP
72/102
2004 Prentice Hall, Inc. All rights reserved.
33.8 ActiveX Data Objects (ADO)
Object/Collection DescriptionConnection object Connects to the data source.Command object Contains the query that interacts with the database (the data
source) to manipulate data.Parameter object Contains information needed by a Command object to query
the data source.Parameters collection
Contains one or more Parameter objects.
Error object Created when an error occurs while accessing data.Errors collection Contains one or more Error objects.Recordset object Contains zero or more records that match the database query.
Collectively, this group of records is called a recordset .Field object Contains the value (and other attributes) of one data source
field.Fields collection Contains one or more Field objects.Property object Contains a characteristic of an ADO object.Properties collection
Contains one or more Property objects.
Record object Contains a single row of a Recordset .Stream object Contains a stream of binary data.
Fig. 33.24 Some ADO object and collection types.
73
33.9 Accessing a Database from an Active
7/31/2019 Csc 318 - Lecture 12-1 - ASP
73/102
2004 Prentice Hall, Inc. All rights reserved.
gServer Page
Web applications Communicating with databases
Use ActiveX Data Objects (ADO) Provides uniform way for programs to connect with
databases
Three-tier distributed applications User interface
Created with XHTML, DHTML or XML Contains ActiveX controls, client-side scripts, Java applets
Communicate directly with business logic Business logic Database access May reside on separate computers
74
33.9 Accessing a Database from an Active
7/31/2019 Csc 318 - Lecture 12-1 - ASP
74/102
2004 Prentice Hall, Inc. All rights reserved.
gServer Page
Web applications, cont. Three-tier distributed applications, cont.
Web servers build middle tier Provide business logic
Manipulates databases Communicates with client Web browsers
ASP communications with databases Use SQL-based queries ADO handled specifics
Through OLE DB Databases provide data source for dynamic content
Allows users who are not familiar with Web languages to create Webpages Restrict access
Password protection Query Access database
7/31/2019 Csc 318 - Lecture 12-1 - ASP
75/102
Outline7625
26
27 If true, errorString
7/31/2019 Csc 318 - Lecture 12-1 - ASP
76/102
2004 Prentice Hall, Inc.All rights reserved.
28
29
30
31
3233
34
35
36
37
database.asp(2 of 2)
Err object Number propertycontains VBScript errornumber. Tests if error hasoccurred.
variable is assignedXHTML text containingerror number and message Error number and message
concatenated to variableerrorString
77
33.9 Accessing a Database from an Active
7/31/2019 Csc 318 - Lecture 12-1 - ASP
77/102
2004 Prentice Hall, Inc. All rights reserved.
Server PageFig. 33.26 Error messages sent to login.asp by database.asp .
Outline781
2
3
7/31/2019 Csc 318 - Lecture 12-1 - ASP
78/102
2004 Prentice Hall, Inc.All rights reserved.
4
5
6
7
89
10
11
12
13
14
15
16
17
18
19
20
2122
23
24
25
login.asp(1 of 7)
Assigns SQL queryto session variable
queryExecutes database.asp to retrievelogin IDs from the database
Outline7926
27
28
7/31/2019 Csc 318 - Lecture 12-1 - ASP
79/102
2004 Prentice Hall, Inc.All rights reserved.
login.asp(2 of 7)
29
30
31
32
3334
35
36
37
38
39
40
41
42
43
44
45
4647
Tests if session variableerrorString value isempty string
Lines 39-41 test is session variableloginFailure is True
Outline804849
50
7/31/2019 Csc 318 - Lecture 12-1 - ASP
80/102
2004 Prentice Hall, Inc.All rights reserved.
login.asp(3 of 7)
51
52
53
54
5556
57
58
59
60
61
62
63
64
65
66
67
68
69
70
select structure builds drop-down list of loginID s
Requests loginID cookie
Selects the returning userslogin ID option
Build loginID options
Outline81
71
72
73
7/31/2019 Csc 318 - Lecture 12-1 - ASP
81/102
2004 Prentice Hall, Inc.All rights reserved.
74
75
76
77
7879
80
81
82
83
84
85
86
87
88
89
90
9192
93
94
login.asp(4 of 7)
If false, print errormessage to user
Outline82
95
96
97
7/31/2019 Csc 318 - Lecture 12-1 - ASP
82/102
2004 Prentice Hall, Inc.All rights reserved.
login.asp(5 of 7)
98
99
100
101
102103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Tests for EOF
If statement tests whetheroption needs to beselected
found set to False before loop
Outline83
120
121
122
If statement writesselected for an
7/31/2019 Csc 318 - Lecture 12-1 - ASP
83/102
2004 Prentice Hall, Inc.All rights reserved.
login.asp(6 of 7)
123
124
125
126
127128
129
130
131
132
selected for anoption
Once selected is
written for an option ,found set to true
Determines whether currentrecords loginID field isequal to loginID cookie
Outline84
133
134
135
7/31/2019 Csc 318 - Lecture 12-1 - ASP
84/102
2004 Prentice Hall, Inc.All rights reserved.
login.asp(7 of 7)
136
137
138
139
140141
142
143
144
145
146
147
148
149
while loop (lines 107-130) iteratesthrough loginData s records Sets option value to
current login ID
Writes option display ascurrent login ID
Increments the record set pointerto next record
8533.9 Accessing a Database from an Active
7/31/2019 Csc 318 - Lecture 12-1 - ASP
85/102
2004 Prentice Hall, Inc. All rights reserved.
Server PageFig. 33.27 ASP document that allows the user to log in to a site.
8633.9 Accessing a Database from an Active
7/31/2019 Csc 318 - Lecture 12-1 - ASP
86/102
2004 Prentice Hall, Inc. All rights reserved.
Server PageFig. 33.27 ASP document that allows the user to log in to a site.
Outline 871
2
3 Check whether password field is empty or id
7/31/2019 Csc 318 - Lecture 12-1 - ASP
87/102
2004 Prentice Hall, Inc.All rights reserved.
4
5
6
7
89
10
11
12
13
14
1516
17
18
19
20
21
2223
24
submitlogin.asp(1 of 2)
field is empty or idloginID field containsdefault value
WHEREspecifies acondition on which recordsare selected
Executes database.asp toquery database
Sets reference loginData tosession variable loginData (contains records matching
query.)
Checks password against thepassword in recordset
If so, variableloginFailure set totrue , client redirectedback to login.asp
Outline 8825
26
27
If true line writes forms loginID
Sets session variableSets cookies expiration date tocurrent date plus 3 days
7/31/2019 Csc 318 - Lecture 12-1 - ASP
88/102
2004 Prentice Hall, Inc.All rights reserved.
28
29
30
31
3233
34
35
36
37
38
39
40
41
42
43
submitlogin.asp(2 of 2)
If true, line writes forms loginID value as cookie named loginID
loginFailure valueto False
current date plus 3 days
Calls Server method Transfer toredirect client to instantpage.asp
Otherwise loginFailure set to Trueand client is redirected to login.asp
8933.9 Accessing a Database from an Active
7/31/2019 Csc 318 - Lecture 12-1 - ASP
89/102
2004 Prentice Hall, Inc. All rights reserved.
Server PageFig. 33.28 ASP document that validates user login.
9033.9 Accessing a Database from an Active
S P
7/31/2019 Csc 318 - Lecture 12-1 - ASP
90/102
2004 Prentice Hall, Inc. All rights reserved.
Server PageFig. 33.28 ASP document that validates user login.
9133.9 Accessing a Database from an Active
S P
7/31/2019 Csc 318 - Lecture 12-1 - ASP
91/102
2004 Prentice Hall, Inc. All rights reserved.
Server PageFig. 33.29 Cookies folder before and after cookie creation.
92
33.10 Server-Side ActiveX Components
7/31/2019 Csc 318 - Lecture 12-1 - ASP
92/102
2004 Prentice Hall, Inc. All rights reserved.
p
ActiveX controls on the server with no GUI Make features available in ASP AdRotator ActiveX component
Rotates advertisements on a Web page Randomly displays one of several advertisements
Minimizes space on a Web page committed to advertisements Client does not have to support ActiveX technologies (on the
server)
PageCounter ActiveX component
Page hit counter
93
33.10 Server-Side ActiveX Components
7/31/2019 Csc 318 - Lecture 12-1 - ASP
93/102
2004 Prentice Hall, Inc. All rights reserved.
p
Component name DescriptionMSWC.BrowserType ActiveX component for gathering information about the
clients browser (e.g., type, version). MSWC.AdRotator ActiveX component for rotating advertisements on aWeb page.
MSWC.NextLink ActiveX component for linking Web pages together.MSWC.ContentRotator ActiveX component for rotating HTML content on a
Web page.MSWC.PageCounter ActiveX component for storing the number of times a
Web page has been requested.MSWC.Counters ActiveX components that provide general-purpose
persistent counters.MSWC.MyInfo ActiveX component that provides information about a
Web site (e.g., owner name, owner address).Scripting.FileSystemObject
ActiveX component that provides an object library for
accessing files on the server or on the servers network. ActiveX Data Objects (ADO)Data Access Components
ActiveX components that provide an object libraryfor accessing databases.
Fig. 33.30 Some server-side ActiveX components.
Outline 941
2
3
4
7/31/2019 Csc 318 - Lecture 12-1 - ASP
94/102
2004 Prentice Hall, Inc.All rights reserved.
4
5
6
7
89
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
component.asp(1 of 4)
Outline 9525
26
27
28Sends advertisement as HTML to client. Method
7/31/2019 Csc 318 - Lecture 12-1 - ASP
95/102
2004 Prentice Hall, Inc.All rights reserved.
28
29
30
31
3233
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
component.asp(2 of 4)
Creates AdRotator component instance,
assigns it reference rotator
GetAdvertisement called using reference rotator .Retrieves advertisements from config.txt
Obtains information about users browser
Check property VBScript value
Test JavaScript property
Outline 9651
52
53
54
BrowserType objects Browser , Version and MinorVer properties
7/31/2019 Csc 318 - Lecture 12-1 - ASP
96/102
2004 Prentice Hall, Inc.All rights reserved.
54
55
56
57
5859
60
61
62
63
64
65
66
67
68
69
70
71
72
component.asp(3 of 4)
can obtain similar client information
TestsCookies
property to determine if browser supports cookies
Increments number of hits by one
Passes server variable keyHTTP_USER_AGENTtoServerVariables , obtains string
containing user information
Outline 9773
74
75
76
Returns number of hits
7/31/2019 Csc 318 - Lecture 12-1 - ASP
97/102
2004 Prentice Hall, Inc.All rights reserved.
component.asp(4 of 4)
76
77
78
79
98
33.10 Server-Side ActiveX Components
7/31/2019 Csc 318 - Lecture 12-1 - ASP
98/102
2004 Prentice Hall, Inc. All rights reserved.
pFig. 33.31 Demonstrating server-side ActiveX components.
99
33.10 Server-Side ActiveX Components
7/31/2019 Csc 318 - Lecture 12-1 - ASP
99/102
2004 Prentice Hall, Inc. All rights reserved.
pFig. 33.31 Demonstrating server-side ActiveX components.
100
33.10 Server-Side ActiveX Components
7/31/2019 Csc 318 - Lecture 12-1 - ASP
100/102
2004 Prentice Hall, Inc. All rights reserved.
Fig. 33.31 Demonstrating server-side ActiveX components.
Outline 1011
2
3
4
Header containsREDIRECT file URL
Advertisement dimensions
Image URL, destination URL,
7/31/2019 Csc 318 - Lecture 12-1 - ASP
101/102
2004 Prentice Hall, Inc.All rights reserved.
4
5
6
7
89
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
config.txt(1 of 1)
Asterisk separates headerfrom advertisements
Advertisement dimensionsalt value, image display ratio
Outline 1021
2
3
4
7/31/2019 Csc 318 - Lecture 12-1 - ASP
102/102
redirect.asp(1 of 1)
4
5
6
7
89
Top Related