|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
In addition, you can use the ADO with your server-side scripts to query back-end databases and integrate the query results into a dynamically generated page. A server-side script, for example, can communicate a SQL query to the ADO. The ADO, in turn, will pass the query to a database server. The database server processes the query and sends the results back to the ADO. The ADO then returns the results to the Active Server Page script. Finally, the script uses the query data to generate and send an HTML page to the browser. As you can see, each component within the architecture performs a specific role, and each component communicates with its immediate neighbor to get the job done.
Building Active Server Page ApplicationsYou can use the same technologies and languages you use to implement client-side scripting. You can use Visual Basic 5, for example, to create ActiveX controls and Active Server components. You can use VBScript to bring together Java applets, ActiveX controls (or Active Server components), and HTML to create ASP. The chief ingredients in any ASP application are scripted instructions embedded in an HTML document. When a browser requests a file containing an Active Server Page document, the server parses out and executes the scripted instructions. Any HTML output from the script is inserted back into the document in place of the original script code. The result is a pure HTML page that is sent back to the browser.
To execute a script on the server, you must include the RUNAT=SERVER option in your <SCRIPT> tags. The code is as follows: <SCRIPT LANGUAGE=VBScript RUNAT=SERVER> <SCRIPT> tags without this attribute define scripts that are to run on the client side. Listing 33.2 shows some script code that will execute on the client. Notice the line of code that displays a message box. Because the script will execute on the client, displaying a message box is meaningful. Listing 33.2 A Client-Side Script <SCRIPT LANGUAGE=VBScript> <!-- Option Explicit Dim validCreditCardNumber Sub Submit_OnClick validCreditCardNumber=True Call CheckCreditCardNumber(CreditCardNumberField.Value, Please enter your credit card number.) If validCreditCardNumber then Msgbox Thank you for your order End if End Sub </SCRIPT> If you tried to execute the same script on the server, displaying a message box would be meaningless because no user interface exists on the server. As a result, the server will bypass the line of code that displays the message box. The server-side scripts you embed inside of HTML code should reside in a text file with the extension .asp. An HTML file is a text file the browser can render on the client machine. The HTML file has the extension .htm or .html. Similarly, an ASP file is a text file the IIS will process on the server. Within an ASP file, you integrate server components through your scripted instructions. Microsoft recommends using VBScript or JScript as your default ASP scripting language.
Listing 33.3 shows an example of an ASP file done with VBScript, the scripting language discussed in the first portion of this chapter. Listing 33.3 A Sample ASP File <HTML> <HEAD> <TITLE>Hello World in ASP</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <% === Active Server Scripting begins sub HelloWorld() dim Greeting Greeting=Hello World! Response.write Greeting End sub %> <% Call HelloWorld %> === Calling the Active Server subroutine </BODY> </HTML> As you can see, this ASP file includes both traditional HTML and scripted instructions. Note that all script code is enclosed within the <% %> tags. Listing 33.4 shows a more complex ASP example that uses three of the five ASP component objects (Session, Response, and Request) to process information. First, you will retrieve information from the form using the Request object and store the information within the Session objects variables. Within this example, you will use the Session variables User_ID, nba_Online, and nfl_Online to store information from the form fields User_Id, nba_online, and nfl_online. Next, you will check whether the User_Id variable is empty. If the variable is empty, you will use the Response objects Redirect method to redirect the browser to the invalid.htm file. If the variable is not empty, you will use the Request object to retrieve the report_type variables value. If the value is nba and the value of the Session variable nba_Online=Y, you will use the Response objects Redirect method to redirect the browser to the latest_nba.htm file. The latest_nba.htm file, in turn, will display the latest NBA scores. On the other hand, if the value of the Session variable nba_Online=N, you will redirect the browser to the invalid.htm file. You will process similarly for the nfl_Online option. In the next section, you will learn more about these ASP objects and their variables, properties, methods, and events.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |