html5-img
1 / 62

ASP Working with Databases Dr. Awad Khalil Computer Science Department AUC

ASP Working with Databases Dr. Awad Khalil Computer Science Department AUC. Active Server Pages (ASP). Outline 1. Introduction 2. Accessing a Database from an Active Server Page 3. Server-Side ActiveX Components 4. Internet and World Wide Web Resources.

stamos
Download Presentation

ASP Working with Databases Dr. Awad Khalil Computer Science Department AUC

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. ASP Working with Databases Dr. Awad Khalil Computer Science Department AUC

  2. Active Server Pages (ASP) Outline 1. Introduction 2. Accessing a Database from an Active Server Page 3. Server-Side ActiveX Components 4. Internet and World Wide Web Resources

  3. Accessing a Database from an Active Server Page • ASP includes the Microsoft ActiveX Data Object (ADO) library which supports database interaction in ASP with a variety of programming tools. • In ASP, the connection object comes from a class called ADODB.Connection, which is one of the classes in the ADO library.

  4. ODBC (Open DataBase Connectivity) • ODBC is a Microsoft standard for database interaction and connection that is part of the Windows operating system. • Users can register data sources with ODBC so that applications can easily access them. • For a Web application to use an ODBC data source, the source must be registered on the Web Server computer. • In order for a JavaScript program to interact with a database, it must create an ADO Connection object and connect to the database. The following two lines of JavaScript code can be added to an ASP script to create a Connection object, store the object in a variable named conn, and open a connection to the database named bighitmdb. Conn = Server.CreateObject(“ADODB.Connection”); Conn.Open(“bighitmdb”);

  5. Accessing a Database from an Active Server 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

  6. Accessing a Database from an Active Server 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 Web pages • Restrict access • Password protection • Query Access database

  7. Executing SQL SEECT Queries with ASP • To generate this page, the Web application would need to create and execute two SQL select queries: One fetches the first and last name of the customer from BigHit’s Customer table. The other fetches the list of all that customer’s rentals from the Rental, Video, and Movie tables.

  8. // connect to database conn = Server.CreateObject("ADODB.Connection"); conn.Open("bighitmdb"); // get parameter values var accountId = Request.QueryString("accountID"); // construct SQL query to fetch customer name var customerQuery = "select lastName, firstName from Customer“ + " where accountId = "+accountId; // execute the query var customer = conn.Execute(customerQuery); // get the first and last names from the query result var firstName = customer(“firstName”); var lastName = customer(“lastName”); customer.close(); printHeader("Outstanding Rentals","for customer "+firstName+” “+lastName); Clock.aspsends Web server’s date and time to the client as XHTML markup<% %> scripting delimeter@LANGUAGE processing directiveOption ExplicitFormatDateTimeNow vbLongDate formatResponse.writeTime

  9. Fetching and Displaying Information form more than one table // get rentals for account and print as table var rentalQuery = "select v.videoId, title, dateRented, dateDue" + " from Rental r, Video v, Movie m " + " where v.videoId = r.videoId and v.movieId = m.movieId" + " and r.accountId = "+ accountId; //var rentals = conn.Execute(rentalQuery); var rentals = executeSQL(rentalQuery); // execute SQL and add to log %> <center><table border=2> <caption>Current Rentals for Account <%= accountId %></caption> <tr> <th>Video ID</th><th>Title</th> <th>Date Rented</th><th>Date Due</th> </tr> <% while(!rentals.eof){ %> <tr> <th><%=rentals("videoId")%></th> <td><%=rentals("title")%></td> <td><%=rentals("dateRented")%></td> <td><%=rentals("dateDue")%></td> </tr> <% rentals.movenext(); } rentals.close(); rentals = null; conn.close();%> </table>

  10. Fetching and Displaying Information form more than one table

  11. Creating Objects from Queries • We can organize the processing of query results by writing functions to process queries that will occur in many Web applications. • The following function (custlookupform) allows creating a customer object from information stored in the database: function lookupCustomer(conn, id) { customer = new Object(); customerSQL="select * from Customer where accountId="+id; custSet = conn.Execute(customerSQL); // check to see if any row was returned if (custSet.eof) { // no customer with this accountId return customer // return empty object } customer.accountId = custSet("accountId"); customer.firstName = custSet("firstName"); customer.lastName = custSet("lastName"); customer.street = custSet("street"); customer.city = custSet("city"); customer.state = custSet("state"); customer.zipcode = custSet("zipcode"); return customer; }

  12. A General Purpose Query Execution Script • Suppose that we create an HTML form that allows users to type an SQL select statement and submit a request for it to be executed. • When the user clicks the submit button, he will expect the result to be a Web page that displays the results of executing the select statement as an HTML table.

  13. Sqlform.asp <%@LANGUAGE="JScript"%> <!-- sqlform.asp --> <html> <!-- #include file="bighittools.js" --> <% startApplication("sqlform.asp"); printHeader("Query Execution","Please enter an SQL select statement"); %> <center> <form method="GET" action="sqlexec.asp"> <table> <tr><th>Enter Select Statement</th> <td><textarea cols="40" rows="6" name="sqlQuery"></textarea></td></tr> </table><br> <input type="submit"> <input type="reset"> </form> </center> <% printFooter("sqlform.asp"); endApplication("sqlform.asp"); %> </html>

  14. Sqlexec.asp <%@LANGUAGE="JScript"%> <!-- sqlexec.asp --> <html> <!-- #include file="bighittools.js" --> <% startApplication("sqlexec.asp"); // get parameter values var conn, sqlQuery, results; sqlQuery = Request("sqlQuery"); printHeader("Execution of Query",sqlQuery); // connect to database conn = Server.CreateObject("ADODB.Connection"); conn.Open("bighitmdb"); // execute query try {// we may get an error in executing the query var numRowsAffected; //results = conn.Execute(sqlQuery); results = executeSQL(sqlQuery); printTable(results,Response); } catch (exception) { Response.write("<table><center>\n"); Response.write("<caption>Unable to process query</caption>\n"); Response.write("<tr><th>Error returned from database</th><td>"); Response.write(exception.description+"<br>\n"); Response.write("</tr></table></center>\n"); //throw exception; } printFooter("sqlexec.asp"); endApplication("sqlexec.asp"); %> </html>

  15. Results of Executing Sqlexec.asp

  16. The Recordset Object – Positioned on the first row

  17. The Recordset Object • The oval in the upper left represents the variable resultswhose value is the Recordset object. • The Recordset object has a collection called fields that contains one field for each column. • Each field object contains the name, type, and value of a single attribute. • Object fields has a property called count with value 8 – the number of fields in the row. • Each field has two properties, a name and a value. • The information needed to generate the Web page can be obtained as follows: • The number of columns in the result is the value of fields.count • The name of the first column is fields(0).name, and the value of the first column is fields(0).value. • … etc.

  18. The Function printTable function printTable(results) { // print the rows of the table as an HTML table // results must be an ADO RecordSet object var numCols = results.fields.count; Response.write("<center><table cellpadding=3><tr>\n"); // write names of columns for (col=0; col<numCols; col++) { Response.write("<th>"+results.fields(col).name+"</td>\n"); } Response.write("</tr>\n"); // write rows of data while (!results.eof) { Response.write("<tr>"); for (col=0; col<numCols; col++) { Response.write("<td>"+results(col).value+"</td>\n"); } results.movenext(); Response.write("</tr>"); } Response.write("</table></center><br>\n"); }

  19. Inserting Data to a Database - newcustmerform.asp <%@LANGUAGE="JScript"%> <html> <!-- #include file="bighittools.js" --> <% startApplication("newcustomerform.asp"); printHeader("Please Enter Your Information","New customer information"); %> <form method="GET" action="newcustomer.asp"><center> <table> <tr><th>First Name: </th><td><input type="text" name="firstName" size = "25"> </td></tr> <tr><th>Last Name: </th><td> <input type="text" name="lastName" size = "25"></td></tr> <tr><th>street: </th><td><input type="text" name="street" size = "25" ></td></tr> <tr><th>City: </th><td><input type="text" name="city" size = "25"></td></tr > <tr><th>Country: </th><td><input type="text" name="state" size = "25"></td ></tr> <tr><th>Zipcode: </th><td><input type="text" name="zipcode" size = "25" ></td></tr> </table><br> <input type="submit" value="Submit"> <input type="reset"> </center></form> <% printFooter("newcustomerform.asp"); endApplication("newcustomerform.asp"); %> </html>

  20. Inserting Data to a Database

  21. Confirm EnteredData to a Database – newcustomer.asp <%@LANGUAGE="JScript"%> <html> <!-- #include file="bighittools.js" --> <% startApplication("newcustomer.asp"); printHeader("Please Confirm","New customer information"); firstName = Request("firstName"); lastName = Request("lastName"); street = Request("street"); city = Request("city"); state = Request("state"); zipcode = Request("zipcode"); %> <form method="GET" action="addcustomer.asp"><center> <table> <tr><th>First Name: </th><td><%=firstName %> </td></tr> <tr><th>Last Name: </th><td><%=lastName %></td></tr> <tr><th>street: </th><td><%=street %></td></tr> <tr><th>City: </th><td><%=city %></td></tr> <tr><th>Country: </th><td><%=state %></td></tr> <tr><th>Zipcode: </th><td><%=zipcode %></td></tr> </table><br> <input type="submit" value="Confirm"> <input type="reset"> <!-- hidden fields to hold customer info--> <input type="hidden" name="firstName" value="<%=firstName%>"> <input type="hidden" name="lastName" value="<%=lastName%>"> <input type="hidden" name="street" value="<%=street%>"> <input type="hidden" name="city" value="<%=city%>"> <input type="hidden" name="state" value="<%=state%>"> <input type="hidden" name="zipcode" value="<%=zipcode%>"> </center></form> <% printFooter("newcustomer.asp"); endApplication("newcustomer.asp"); %> </html>

  22. Confirm Entered Data to a Database – newcustomer.asp

  23. Inserting the Data – addcustomer.asp <%@LANGUAGE="JScript"%> <!-- makecustomer.asp --> <html> <!-- #include file="bighittools.js" --> <% startApplication("makecustomer.asp"); // get parameter values var customer, newId; customer = makeCustomer(Request); with (customer) { printHeader("New Customer Receipt","Welcome "+firstName+" "+lastName); // connect to database conn = Server.CreateObject("ADODB.Connection"); conn.Open("bighitmdb"); // get new account ID as maximum current account ID plus 1 //maxId = conn.Execute("select max(accountId) from Customer"); maxId = executeSQL("select max(accountId) from Customer"); newId = maxId(0) + 1;

  24. Inserting the Data – addcustomer.asp // insert customer newCustSQL = "insert into Customer " +"(accountId, firstName, lastName, street, city, state, zipcode)" +" values(" +newId+", '" +sqlString(firstName)+"','" +(lastName)+"', '" +sqlString(street)+"', '" +sqlString(city)+"', '" +sqlString(state)+"', '" +sqlString(zipcode)+"')"; //Response.write("<br>SQL: "+newCustSQL+"<br>"); //conn.Execute(newCustSQL); // replaced with function call executeSQL(newCustSQL); } // end with customer // fetch customer information from the database customer = lookupCustomer(conn,newId); if (customer.accountId!=newId) {// no new customer Response.Write("<br>No new customer with account ID: "+newId+"<p>\n"); customer = makeCustomer(Request); } printCustomerTable(customer); printFooter("addcustomer.asp"); endApplication("makecustomer.asp"); %> </html>

  25. Inserting Data to the Database – newcustomer.asp

  26. Displaying Inserted Data

  27. Displaying Inserted Data

  28. Server-Side ActiveX Components Using Cookies - Login in Application • This application controls user’s access to the content builder application through authenticating the user by username and password information which are stored in the database login.mdb. The application is made of three scripts: • login.asp: providing the user interface, displaying the form, and error messages in case of access failure. • database.asp: connecting to the database, executing the query to get users’ access information, communicating with login.asp through session tracking. • submitlogin.asp: check user login information, create a cookie to store loginID information, and communicating with login.asp through session tracking.

  29. Ignores errors until end of script Server method CreateObject creates ADODB.Connection Declares session variable errorString Method Open opens database specified by ODBC System DSN (login) When Open finishes executing, points to first record or EOF if no records were found loginData reference is set to an ADODB.recordset object errorHandlerLog processes errors Open method is passed string containing SQL query and ADODB.Connection object errorHandlerLogcalled again Err object Number property contains VBScript error number. Tests if error has occurred. Lines 25-36 defineerrorHandlerLog If true, errorSrting variable is assigned XHTML text containing error number and message Error number and message concatenated to variable errorString Sets session variable loginData to variable loginData which references the ADODB.Recordset containing all records matching SQL query 1 <% @LANGUAGE = VBScript %> 2 3 <% 4 ' Fig. 22 : database.asp 5 ' ASP document for interacting with the database 6 Option Explicit 7 8 Dim connection, loginData 9 10 ' provide error handling code 11On Error Resume Next 12 Session( "errorString" ) = "" 13 14 Set connection = Server.CreateObject( "ADODB.Connection" ) 15Call connection.Open( "login" ) 16Call errorHandlerLog() 17 18 ' create the record set 19Set loginData = Server.CreateObject( "ADODB.Recordset" ) 20Call loginData.Open( Session( "query" ), connection ) 21Set Session( "loginData" ) = loginData 22 23Call errorHandlerLog() 24 25Sub errorHandlerLog() 26If Err.Number <> 0Then 27 Dim errorString 28 29 errorString = Session( "errorString" ) 30 errorString = errorString & "<p class = " & _ 31 Chr( 34 ) & "error" & Chr ( 34 ) & ">Error (" _ 32 & Err.Number & ") in " & Err.Source & "<br />" & _ 33 Err.Description & "</p><br />" 34 Session( "errorString" ) = errorString 35 End If 36 End Sub 37 %> Database.aspconnects to, and queries an Access databaseCreateObjectADODB.Connectioncontains functionality necessary to connect to databaseerrorHandlerLog

  30. Assigns SQL query to session variable query Executes database.asp to retrieve login IDs from the database 1 <% @LANGUAGE = VBScript %> 2 3 <% 4 ' Fig. 23 : login.asp 5 ' ASP document to login to instantpage.asp 6 Option Explicit 7 8 ' create the SQL query 9 Session( "query" ) = "SELECT loginID FROM Users" 10Call Server.Execute( "database.asp" ) 11 %> 12 13 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 14 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 15 16 <html xmlns = "http://www.w3.org/1999/xhtml"> 17 18 <head> 19 <title>Login Page</title> 20 21 <style type = "text/css"> 22 table { text-align:center; 23 font-size:12pt; 24 color:blue; 25 font-size:12pt; 26 font-family:arial, sans-serif } 27 .error { color:red } 28 </style> 29 30 </head> 31 32 <body> 33 34 <!-- #include virtual="/includes/header.shtml" --> 35 <% Login.aspIdentifies users by prompting them for login name and password. Data is stored in Access database login.mdbsubmitlogin.asp validates the user’s login

  31. Tests if session variable errorString value is empty string Lines 39-41 test is session variable loginFailure is True select structure builds drop-down list of loginIDs Requests loginID cookie Selects the returning user’s login IDoption Build loginID options 36If Session( "errorString" ) = ""Then 37 ' if this is a return after a failed attempt, 38 ' print an error 39If Session( "loginFailure" ) = TrueThen%> 40 <p class ="error">Login attempt failed, 41 please try again</p> 42 <%End If 43 44 ' begin the form %> 45 <p>Please select your name and enter 46 your password to login:</p><br /> 47 48 <form action ="submitlogin.asp" method = "post"> 49 50 <!-- format the form using a table --> 51 <table border ="0"> 52 <tr> 53 <td>Name:</td> 54 55 <td> 56 <select name = "loginID"> 57 <option value = "noSelection"> 58 Select your name</option> 59 60 <% 61If Request.Cookies( "loginID" ) <> ""Then 62 Call BuildReturning() 63 Else 64 Call BuildNewUser() 65 End If 66 %> 67 </select> 68 </td> 69 </tr> 70 Login.aspPrompts user for login name and password. Information is stored in Access database opened in database.asp If false, line 89 prints error message to user If true, login failure message prints to user and prompts new login

  32. 71 <tr> 72 <td>Password:</td> 73 <td><input type = "password" 74 name = "password" /></td> 75 </tr> 76 77 <tr> 78 <td></td> 79 <td align = "left"> 80 <input type = "submit" value = "Log Me In" /> 81 </td> 82 </tr> 83 </table> 84 </form> 85 86 <!-- #include virtual="/includes/footer.shtml" --> 87 <% 88 Else 89 Call Response.Write( Session( "errorString" ) ) 90 End If 91 %> 92 </body> 93 </html> 94 95 <% 96 ' builds the option items for loginIDs and writes 97 ' selected for the loginID of the returning user 98 Sub BuildReturning() 99 Dim found, loginData 100 101Set loginData = Session( "loginData" ) 102 103 ' pull user names from the record set to populate the 104 ' dropdown list Login.asp Prompts user for login name and password. Information is stored in Access database opened in database.asp

  33. Tests forEOF found set to false before loop If statement writes selected for an option If statement tests whether option needs to be selected Increments the record set pointer to next record If true, lines 122-124 write selected and set found to true Once selected is written for an option, found set to true Determines whether current record’s loginID field is equal to loginID cookie while loop (lines 107-130) iterates through loginData’s records Writes option display as current loginID Sets option value to current loginID 105 found = False 106 107 While Not loginData.EOF 108 ' create this record's dropdown entry 109%><option 110 <%' if we did not write selected for any option 111 ' before 112If ( Not found ) Then 113 114 ' if the current record's loginID is equal to 115 ' the loginID cookie, then it is the loginID of 116 ' the returning user, and thus we need to write 117 ' selected for this option; in this case we also 118 ' need to signal that we have written selected 119 ' for an option by setting found to True. 120If Request.Cookies( "loginID" ) _ 121 = loginData( "loginID" ) Then 122 Call Response.Write( "selected = " & _ 123 Chr( 34 ) & "selected" & Chr( 34 ) ) 124 found = True 125 End If 126 End If 127%>value = "<% =loginData( "loginID" ) %>"> 128<% =loginData( "loginID" ) %></option> 129<% Call loginData.MoveNext() 130 Wend 131 End Sub 132 133 ' builds the option items for loginIDs without writing 134 ' selected for any loginID 135 Sub BuildNewUser() 136 Dim loginData 137 138 Set loginData = Session( "loginData" ) 139 Login.asp Prompts user for login name and password. Information is stored in Access database opened in database.asp

  34. 140 ' pull user names from the record set to populate the 141 ' dropdown list 142 While Not loginData.EOF 143 ' create this record's dropdown entry 144 %><option value = "<% =loginData( "loginID" ) %>"> 145 <% =loginData( "loginID" ) %></option> 146 <% Call loginData.MoveNext() 147 Wend 148 End Sub 149 %> Login.aspProgram Output

  35. Program Output

  36. Lines 9-13 check whether password field is empty or id loginID field contains default value WHERE specifies a condition on which records are selected Checks password against the password in recordset Sets session variable loginFailure value to False Sets reference loginData to session variable loginData (contains records matching query.) Executes database.asp to query database Sets cookie’s expiration date to current date plus 3 days If true, line writes form’s loginID value as cookie named loginID 1 <% @LANGUAGE = VBScript %> 2 3 <%' Fig. 25.24 : submitlogin.asp 4 ' ASP document to check user's username and password 5 Option Explicit 6 7 ' test if a user name and a password were 8 ' entered. If not, transfer back to the login page. 9If Request( "password" ) = ""Or _ 10 Request( "loginID" ) = "noSelection"Then 11 Session( "loginFailure" ) = True 12 Call Server.Transfer( "login.asp" ) 13 End If 14 15 Dim connection, loginData 16 17 ' create the SQL query 18 Session( "query" ) = _ 19"SELECT * FROM Users WHERE loginID = '" & _ 20 Request( "loginID" ) & "'" 21 22Call Server.Execute( "database.asp" ) 23Set loginData = Session( "loginData" ) 24 25If Request( "password" ) = loginData( "password" ) Then 26 27 ' password is OK, adjust loginFailure 28 Session( "loginFailure" ) = False 29 30 ' write a cookie to recognize them the next time they 31 ' go to login.asp 32 Response.Cookies( "loginID" ) = Request( "loginID" ) 33 34 ' give it three days to expire 35 Response.Cookies( "loginID" ).Expires = Date() + 3 Submitlogin.aspTakes values passed by login.asp and checks values against Users table in databaseIf match is found, user is redirected to instantpage.asp. If not, user is redirected to login.asp. If so, variable loginFailure set to true, client redirected back to login.asp

  37. Otherwise loginFailure set to True and client is redirected to login.asp Calls Server method Transfer to redirect client to instantpage.asp 36 37 ' send them to instantpage.asp 38Call Server.Transfer( "instantpage.asp" ) 39 Else 40 Session( "loginFailure" ) = True 41 Call Server.Transfer( "login.asp" ) 42 End If 43 %> Submitlogin.aspProgram Output

  38. Program Output

  39. Accessing a Database from an Active Server Page Fig. 25.25 Cookies folder before and after cookie creation.

  40. Accessing a Database from an Active Server Page Fig. 26 Error messages sent to login.asp by database.asp.

  41. Server-Side ActiveX Components • 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

  42. Server-Side ActiveX Components

  43. Creates AdRotator component instance, assigns it reference rotator Sends advertisement as HTML to client. Method GetAdvertisement called using reference rotator. Retrieves advertisements from config.txt 1 <% @LANGUAGE = VBScript %> 2 3 <% 4 ' Fig. 28 : component.asp 5 ' Demonstrating Server-side ActiveX Components 6 Option Explicit 7 %> 8 9 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 10 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 11 12 <html xmlns = "http://www.w3.org/1999/xhtml"> 13 14 <head> 15 <title>ActiveX Component Example</title> 16 </head> 17 18 <body> 19 20 <strong style = "font-family: arial, sans-serif"> 21 Server-side ActiveX Components 22 </strong> 23 24 <p> 25 <% 26 Dim rotator, browser, information, counter 27 28 ' create an AdRotator object 29Set rotator = Server.CreateObject( "MSWC.AdRotator" ) 30 31 ' use config.txt to send an advertisement to the client 32Call Response.Write( _ 33 rotator.GetAdvertisement( "config.txt" ) ) 34 Component.aspUses AdRotator ActiveX component to rotate one of five flag images. When user clicks flag image, country’s corresponding CIA Fact Book Web page displays.

  44. Obtains information about user’s browser Check property VBScript value If true, lines 48-50 written to client Passes server variable key HTTP_USER_AGENT to ServerVariables, obtains string containing user information BrowserType object’s Browser Version and MinorVer properties can obtain similar client information Lines 46-52 test JavaScript property Tests Cookies property to determine if browser supports cookies 35 ' create a BrowserType object 36Set browser = Server.CreateObject( "MSWC.BrowserType" ) 37 38If browser.VBScript = True Then 39 %> 40 <script language = "VBScript"> 41 Call Msgbox( "Client browser supports VBScript!" ) 42 </script> 43 <% 44 End If 45 46 If browser.JavaScript = TrueThen 47 %> 48 <script language = "JavaScript"> 49 alert( "Client browser supports JavaScript!" ); 50 </script> 51 <% 52 End If 53 54 ' get client's browser information 55 information = "<p>Your browser information is:<br />" & _ 56 Request.ServerVariables( "HTTP_USER_AGENT" ) & _ 57"<br />Browser: " & browser.Browser & " Version: " & _ 58 browser.Version & " Minor version: " & _ 59 browser.MinorVer & "<br />Cookies are " 60 61If browser.Cookies Then 62 information = information & "enabled</p><br />" 63 Else 64 information = information & "disabled</p><br />" 65 End If 66 67 Call Response.Write( information ) 68 Component.asp

  45. Returns number of “hits” Increments number of “hits” by one 69 ' create Page Counter Object 70 Set counter = Server.CreateObject( "MSWC.PageCounter" ) 71Call counter.PageHit() ' page has been "hit" 72 %> 73 </p> 74 75 <p style = "color: blue; font-size: 12pt"> 76 This page has been visited <% =counter.Hits() %> 77 times!</p> 78 </body> 79 </html> Component.asp

  46. Program Output

  47. Program Output

  48. Header contains REDIRECT file URL Image URL, destination URL, alt value, image display ratio Advertisement dimensions Asterisk separates header from advertisements 1 REDIRECT redirect.asp 2 width 54 3 height 36 4 border 1 5 * 6 /images/su-flag.gif 7 http://www.odci.gov/cia/publications/factbook/geos/su.html 8 Sudan Information 9 20 10 /images/eg-flag.gif 11 http://www.odci.gov/cia/publications/factbook/geos/eg.html 12Egypt Information 13 20 14 /images/us.gif 15 http://www.odci.gov/cia/publications/factbook/geos/us.html 16 United States Information 17 20 18 /images/france.gif 19 http://www.odci.gov/cia/publications/factbook/geos/fr.html 20 France Information 21 20 22 /images/germany.gif 23 http://www.odci.gov/cia/publications/factbook/geos/gm.html 23 Germany Information 24 20 25 /images/italy.gif 26 http://www.odci.gov/cia/publications/factbook/geos/it.html 27 Italy Information 28 20 29 /images/spain.gif 30 http://www.odci.gov/cia/publications/factbook/geos/sp.html 31 Spain Information 32 20 Config.txtDescribes the advertisements

  49. 1 <% @LANGUAGE = VBScript %> 2 3 <% 4 ' Fig. 30 : redirect.asp 5 ' Redirection Page for AdRotator Component 6 Option Explicit 7 8 Call Response.Redirect( Request( "url" ) ) 9 %> Redirect.aspRedirects user to country’s CIA page when ad is clicked

More Related