Download presentation
Presentation is loading. Please wait.
Published byOwen Flynn Modified over 9 years ago
1
8 Chapter Eight Server-side Scripts
2
8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process form inputs using Active Server Pages Create a Web application using client- and server-side scripts
3
8 Server-side Scripts Server-side scripts –Scripts that are processed on the Web server, need PWS to process! –Used to create dynamic Web pages that retrieve and display database data and modify data records Active Server Pages –Microsoft-specific Web pages containing server- side scripting commands to process user inputs and create dynamic Web pages that display database data
4
8 Server-side Scripts Figure 8-1: Web site architecture using a server-side script
5
8 Active Server Pages Active Server Page (ASP) –Text file that has an.asp extension and contains server-side script commands that can perform a variety of tasks (retrieve data, update data, query data) –Usually contains HTML commands for creating a formatted Web page Netscape has a server-side scripting technology called LiveWire that is similar to Active Server Pages
6
8 Active Server Pages Since ASPs are processed on a Web server, ASP files must be stored and run from a folder on the Web server (page 271) –They cannot be displayed from a folder on the user’s workstation using a file URL –Programmers often store program files in folders that are named “bin” or have the word “bin” as part of the folder name
7
8 Active Server Pages Access privileges that are available in Personal Web Server (PWS) include: –Read, which only allows users to view HTML documents –Execute, which allows users to run Web pages that contain executable programs as well as scripts –Scripts, which allows users to run Web pages that contain scripts, but do not run Web pages that contain executable programs
8
8 Active Server Pages When creating an ASP, it is good practice to: –First create a static HTML Web page template file that contains all of the HTML tags and formatted text that you want to have displayed on the formatted Web page that is generated by the ASP (page 273) –Then, add the script code for the dynamic components and be certain that the page’s HTML formatting will be correct
9
8 ASP Commands The main difference between ASP files and HTML document files is ASP files contain ASP script code lines along with HTML commands in the Web page body –Script commands like HTML commands, can span multiple lines
10
8 ASP Commands The beginning and ending points of ASP script code lines are signaled by script delimiter tags –The opening script delimiter tag is an opening angle bracket and a percent sign (<%) –The closing script delimiter tag is a percent sign and a closing angle bracket (%>)
11
8 Displaying Database Data in an ASP To create an ADO database connection object, you must create a server object –Memory area on the Web server that stores the variables and other information needed to process the ASP Every time the ASP is executed, a new server object must be created
12
8 Create ASP - Overview Create ADO database connection –Create a server object(memory area on the web server that stores the variables and other info needed to process ASP) Open the database connection (ODBC connection using ODBC driver) To retrieve data from database, you create a recordset based on SQL query Display values Close database connection
13
8 Displaying Database Data in an ASP In the code to open an ODBC connection –You must specify the name of the server object, and use the Open method to specify that the object is to be opened –Specify the database type and database location; for an Access database, the database location is the drive letter, folder, path, and database filename
14
8 Displaying Database Data in an ASP Figure 8-5: Code to open an Access database connection object (open and closing script delimeter tags)
15
8 Displaying Database Data in an ASP When finished using a database connection object, close the database connection; this makes its resources available to other Web server processes
16
8 Displaying Database Data in an ASP In a Web page with server-side scripts: –All of the server-side commands enclosed in script delimiter tags are removed by the Web server when the Web page is processed –Only the finished HTML commands are sent to the user’s browser for display
17
8
18
8 Retrieving Input Parameters into an ASP To retrieve the value of a variable that is passed as a URL parameter, use the Request object –An object within an ASP that stores information that is sent from a user’s browser to the Web server The Request object has a Querystring property, which contains the name of the variable whose value will be retrieved as a URL parameter
19
8 Retrieving Input Parameters into an ASP It can be tricky to create SQL queries that use URL parameters - You must concatenate text strings, blank spaces, and variable values together so that the variable string is formatted correctly
20
8
21
8 Debugging ASP Scripts The common errors of forgetting to save a modified ASP file, or displaying a cached version of a previous file, apply to ASPs as well as client-side scripts When calling an ASP from another Web page and passing URL parameter values, always confirm the parameter name/value pairs are passed correctly by viewing the URL of the hyperlink that calls the ASP
22
8 Debugging ASP Scripts A common error in ASP scripts occurs when inadvertently omitting an opening or closing script delimiter tag Figure 8-16: Source code with omitted script delimiter tag
23
8 Debugging ASP Scripts When looking for causes of errors, always look at the code lines immediately before the line reported in the error message If you cannot locate the error visually, the next step is to systematically locate the code line that is causing the error In an ASP, you can track script execution by adding debugging messages
24
8
25
8 Creating Client-side Scripts in ASPs Preprocessing the ASP –Use client-side scripts within ASPs so that when the user clicks a button on an HTML form, the form runs a client-side script that is embedded within the HTML code on the ASP Creating and Retrieving Cookie Values Using a Client Side Script
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.