60 likes | 67 Views
Active Server Pages (ASP). ASP: Simplest Example. The simplest example:. <HTML> <BODY> Hello World ! </BODY> </HTML>. <% For i=1 to 5 %>. <% Next %>. Line <%= i %>. Additionally ASP may contain code (scripts, ActiveX controls) within <% . . . %> which is interpreted by the server.
E N D
Active Server Pages (ASP) ASP: Simplest Example The simplest example: <HTML> <BODY> Hello World ! </BODY> </HTML> <% For i=1 to 5 %> <% Next %> Line <%= i %> Additionally ASP may contain code (scripts, ActiveX controls) within <% . . . %> which is interpreted by the server. Connect to a database (DB) run example: run example: run example: Display a variable. Swiss Federal Institute of Technology n
Active Server Pages (ASP) ASP: Connection to a DB Connection to a database (DB): Do while not objList.EOF %> <%= objList("PerName") %><BR> <% objList.MoveNext Loop Set objList = objConn.Execute("SELECT * FROM TPersons") objList.Close objConn.Close %> <% Set objConn = Server.CreateObject("ADODB.Connection") <HTML> <BODY> </BODY> </HTML> objConn.Open "IGT-DB" 1. instantiate a server Object for an ADO-DB connection 2. open the connection to the DSN (data source name) 3. issue an SQL command and get results 4. display the results 5. close connection ASP objects and Management run example: n
ASP Session Management ASP: Session Management Browser calls 1st ASP Start Application, i.e. New Application ? y • create Application object • fire Application_OnStart and scan Global.asa n Start Session, i.e • create Session object • create Request object • fire Session_OnStart and scan Global.asa Run ASP end Session, i.e. • fire Session_OnEnd Swiss Federal Institute of Technology n
ASP Session Management ASP: Built in Objects Built in ASP objects(http://www.activeserverpages.com/iishelp/iis/htm/asp/iiwaobb.htm) Swiss Federal Institute of Technology n
Active Server Pages (ASP) ASP: Query a DB from a Form Query a DB from a Form A simple Form: <HTML> <BODY> <FORM METHOD="POST" ACTION="Sample5.asp"> 1st Names to search for: <INPUT NAME="FirstName"> <INPUT TYPE=SUBMIT> </FORM> </BODY> </HTML> run example: QUERY.ASP is called with parameter FirstName Swiss Federal Institute of Technology n
Active Server Pages (ASP) ASP: Display query Results Query a DB from a Form <HTML> <BODY> <% Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open "IGT-DB" FName = Request("FirstName") SQLQuery = "SELECT * FROM Tpersons" + _ "WHERE TPersons.PerFirstName='" & FName & "'" Set objList = objConn.Execute( SQLQuery ) Do while not objList.EOF %> <%= objList("PerName") %><BR> <% objList.MoveNext Loop objList.Close objConn.Close %> </BODY> </HTML> run example: 1. get parameter from form (Request object) 2. add a WHERE clause with this parameter Swiss Federal Institute of Technology n