Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example:...
-
Upload
martha-daniel -
Category
Documents
-
view
215 -
download
0
Transcript of Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example:...
![Page 1: Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)](https://reader036.fdocuments.net/reader036/viewer/2022082711/56649f145503460f94c28231/html5/thumbnails/1.jpg)
Swiss Federal Institute of Technology 1
Active Server Pages (ASP)
n
The simplest example:
Additionally ASP may contain code (scripts, ActiveX controls) within <% . . . %> which is interpreted by the server.
<HTML><BODY>Hello World !</BODY></HTML>
<% For i=1 to 5 %>
<% Next %>
Connect to a database (DB)
Line <%= i %>
ASP: Simplest Example
run example:
![Page 2: Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)](https://reader036.fdocuments.net/reader036/viewer/2022082711/56649f145503460f94c28231/html5/thumbnails/2.jpg)
n
1. instantiate a server Object for an ADO-DB connection
Active Server Pages (ASP)Connection to a database (DB):
<HTML><BODY>
</BODY></HTML>
<% Set objConn = Server.CreateObject("ADODB.Connection")
2. open the connection to the DSN (data source name)
objConn.Open "IGT-DB"
5. close connection
3. issue an SQL command and get results4. display the results
Set objList = objConn.Execute("SELECT * FROM TPersons")
Do while not objList.EOF %><%= objList("PerName") %><BR><% objList.MoveNextLoop
objList.CloseobjConn.Close %>
ASP objects and Management
ASP: Connection to a DB
run example:
![Page 3: Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)](https://reader036.fdocuments.net/reader036/viewer/2022082711/56649f145503460f94c28231/html5/thumbnails/3.jpg)
Swiss Federal Institute of Technology 3
ASP Session Management
n
Browser calls 1st ASP
Start Session, i.e
Run ASP
end Session, i.e.
New Application ?
Start Application, i.e.y
n
• create Application object• fire Application_OnStart and scan Global.asa
• create Session object• create Request object• fire Session_OnStart and scan Global.asa
• fire Session_OnEnd
ASP: Session Management
![Page 4: Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)](https://reader036.fdocuments.net/reader036/viewer/2022082711/56649f145503460f94c28231/html5/thumbnails/4.jpg)
Swiss Federal Institute of Technology 4
ASP Session Management
n
Built in ASP objects (http://www.activeserverpages.com/iishelp/iis/htm/asp/iiwaobb.htm)
Object Collections Properties Methods EventsApplication Contents
StaticObjectsLockUnlock
Application_OnStartApplication_OnEnd
Session ContentsStaticObjects
SessionIDTimeout,Codepage
Abandon Session_OnStartSession_OnEnd
Request Form,QueryStringCookies,ServerVars
TotalBytes BinaryRead
Response Cookies ContentTypeExpires, StatusIsClientConnected
BinaryWriteClear, FlushWrite, End
Server ScriptTimeout CreateObjectMapPathHTMLEncodeURLEncode
ObjectContext SetCompleteSetAbort
ASP: Built in Objects
![Page 5: Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)](https://reader036.fdocuments.net/reader036/viewer/2022082711/56649f145503460f94c28231/html5/thumbnails/5.jpg)
Swiss Federal Institute of Technology 5
Active Server Pages (ASP)
n
Query a DB from a Form
<HTML><BODY><FORM METHOD="POST" ACTION="Sample5.asp">1st Names to search for: <INPUT NAME="FirstName"><INPUT TYPE=SUBMIT></FORM>
</BODY></HTML>
A simple Form:
QUERY.ASP is called with parameter FirstName
ASP: Query a DB from a Form
run example:
![Page 6: Swiss Federal Institute of Technology 1 Active Server Pages (ASP) n The simplest example: Additionally ASP may contain code (scripts, ActiveX controls)](https://reader036.fdocuments.net/reader036/viewer/2022082711/56649f145503460f94c28231/html5/thumbnails/6.jpg)
Swiss Federal Institute of Technology 6
1. get parameter from form (Request object)
Active Server Pages (ASP)
n
2. add a WHERE clause with this parameter
<HTML><BODY><% Set objConn = Server.CreateObject("ADODB.Connection")objConn.Open "IGT-DB"
Query a DB from a Form
FName = Request("FirstName")
Set objList = objConn.Execute( SQLQuery )Do while not objList.EOF %><%= objList("PerName") %><BR><% objList.MoveNextLoopobjList.CloseobjConn.Close %></BODY></HTML>
SQLQuery = "SELECT * FROM Tpersons"
"WHERE TPersons.PerFirstName='" & FName & "'"
+ _
ASP: Display query Results
run example: