1 / 6

ASP: Simplest Example

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.

vbergmann
Download Presentation

ASP: Simplest Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

More Related