ASP Simplest Example Active Server Pages ASP The

  • Slides: 6
Download presentation
ASP: Simplest Example Active Server Pages (ASP) The simplest example: <HTML> <BODY> Hello World

ASP: Simplest Example Active Server Pages (ASP) The simplest example: <HTML> <BODY> Hello World ! </BODY> </HTML> <% For i=1 to 5 %> <% Next %> Line <%= i %> Additionally ASP may contain code (scripts, Active. X controls) within <%. . . %> which is interpreted by the server. Connect a database (DB) Display atovariable. Swiss Federal Institute of Technology runexample: 1 n

ASP: Connection to a DB Active Server Pages (ASP) Connection to a database (DB):

ASP: Connection to a DB Active Server Pages (ASP) Connection to a database (DB): <HTML> <BODY> <% Set obj. Conn = Server. Create. Object("ADODB. Connection") obj. Conn. Open "IGT-DB" Set obj. List = obj. Conn. Execute("SELECT * FROM TPersons") Do while not obj. List. EOF %> <%= obj. List("Per. Name") %><BR> <% obj. List. Move. Next Loop obj. List. Close obj. Conn. Close %> </BODY> </HTML> 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 get results 4. display the results 5. close connection ASP objects and Management example: Swiss Federalrun Institute of Technology 2 n

ASP: Session Management ASP Session Management Browser calls 1 st ASP Start Application, i.

ASP: Session Management ASP Session Management Browser calls 1 st ASP Start Application, i. e. New y • create Application object Application ? • fire Application_On. Start and scan n Global. asa Start Session, i. e • create Session object • create Request object • fire Session_On. Start and scan Global. asa Run ASP end Session, i. e. • fire Session_On. End Swiss Federal Institute of Technology 3 n

ASP: Built in Objects ASP Session Management Built in ASP objects (http: //www. activeserverpages.

ASP: Built in Objects ASP Session Management Built in ASP objects (http: //www. activeserverpages. com/iishelp/iis/htm/asp/iiwaobb. htm) Swiss Federal Institute of Technology 4 n

ASP: Query a DB from a Form Active Server Pages (ASP) Query a DB

ASP: Query a DB from a Form Active Server Pages (ASP) Query a DB from a Form A simple Form: <HTML> <BODY> <FORM METHOD="POST" ACTION="Sample 5. asp"> 1 st Names to search for: <INPUT NAME="First. Name"> <INPUT TYPE=SUBMIT> </FORM> </BODY> </HTML> run example: QUERY. ASP is called with parameter First. Name Swiss Federal Institute of Technology 5 n

ASP: Display query Results Active Server Pages (ASP) Query a DB from a Form

ASP: Display query Results Active Server Pages (ASP) Query a DB from a Form <HTML> <BODY> <% Set obj. Conn = Server. Create. Object("ADODB. Connection") obj. Conn. Open "IGT-DB" FName = Request("First. Name") SQLQuery = "SELECT * FROM Tpersons" + _ "WHERE TPersons. Per. First. Name='" & FName & "'" Set obj. List = obj. Conn. Execute( SQLQuery ) Do while not obj. List. EOF %> <%= obj. List("Per. Name") %><BR> run example: <% obj. List. Move. Next Loop 1. get parameter from form (Request object) obj. List. Close 2. add a WHERE clause with this parameter obj. Conn. Close %> </BODY> </HTML> Swiss Federal Institute of Technology 6 n