McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Java Script Session1 INTRODUCTION.
The Web Warrior Guide to Web Design Technologies
DT228/3 Web Development WWW and Client server model.
Session 13 Active Server Pages (ASP) Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
DT211/3 Internet Application Development Active Server Pages & IIS Web server.
Server-Side vs. Client-Side Scripting Languages
1 Chapter 12 Working With Access 2000 on the Internet.
ASP Tutorial. What is ASP? ASP (Active Server Pages) is a Microsoft technology that enables you to make dynamic and interactive web pages. –ASP usually.
1 Today: Introduction to ASP- Part 1 Explain the client/server architecture Explain Web-based client/server applications Understand the essentials of Active.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Servlets and a little bit of Web Services Russell Beale.
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
INTRODUCTION TO WEB DATABASE PROGRAMMING
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Server- Side technologies Client-side vs. Server-side scripts PHP basic ASP.NET basic ColdFusion.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Server-side Scripting Powering the webs favourite services.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
ASP Introduction Y.-H. Chen International College Ming-Chuan University Fall, 2004.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Tutorial 10 Programming with JavaScript
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Lecture Note 1: Getting Started With ASP.  Introduction to ASP  Introduction to ASP An ASP file can contain text, HTML tags and scripts. Scripts in.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
Lecture Note 8: ASP Including Files and The Global.asa file.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Client-side & Server-side Scripting ©Richard L. Goldman August 5, 2003 Requires PowerPoint 2002 or later for full functionality.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
ASP Mr. Baha & Dr.Husam Osta  What is ASP?  Internet Information Services  How Does ASP Differ from HTML?  What can ASP do for you?  ASP Basic.
ASP – Web Programming Class  Ravi Anand. ASP – Active Server Pages What is ASP? - Microsoft Technology - Can Run using IIS/PWS/Others - Helps us create.
National College of Science & Information Technology.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Tutorial 10 Programming with JavaScript
ASP Explained By: Sarbjit Kaur.
The Request & Response object
Client side & Server side scripting
Cookies A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer.
Presentation transcript:

McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming the Web Chapter 10

10-2 Learning Objectives Get familiar with ASP syntax Use Active Server Pages objects for web applications Learn how to collect information in forms Work with cookies Learn how to set up Server Side Include files

10-3 What is ASP? Microsoft’s Active Server Pages (ASP) technology is a server- side scripting environment. It’s used in creating server-side scripts to automatically perform difficult or repetitious Web management tasks in dynamic web pages. You can write ASP scripts to: –Edit, change or add content to a Web page on the fly –Customize a Web page to make it more useful for individual users –Respond to user queries or data submitted through HTML forms –Access any data or databases and return the results to a browser

10-4 What is ASP? (2) An ASP file is simply an HTML file that can contain text, HTML, XML, and scripts. The core of an ASP file is the script. To run ASP, you need Microsoft’s Internet Information Server which runs under Windows NT 4 and Windows 2000 or the Personal Web Server. Combine HTML and/or XML with a little VBScript or JavaScript, attach the.asp file extension to the file, and you’ve got an Active Server Page.

10-5 How ASP Works An ASP file can contain any combination of HTML, script, or commands. The script can assign values to variables, request information from the server, or combine any set of commands into procedures. It works like this: 1.A browser requests an ASP file from your web server 2.Internet Information Server passes the request to the ASP engine. 3.The ASP engine reads the ASP file, line by line, and executes any commands in the file 4.Finally, the ASP file is returned to the browser as plain HTML which is displayed on the page

10-6 Speaking the Language of ASP Active Server Pages (ASP) technology is language- independent. VBScript and JScript scripting languages are supported right out of the box. In fact, several scripting languages can be used within a single.asp file. VBScript is the default scripting language for ASP so if you omit the language directive the server simply assumes it’s VBScript. You can also use JavaScript as the scripting language by inserting it into the language directive at the top of the page:

10-7 ASP Syntax Welcome to My First ASP Page Welcome The time is now This sends the text to the browser The delimiters,, tells the web server that it must run the enclosed script code before the server transmits the page to the browser This tells the web server to create the entire web page in memory before sending it to the client

10-8 ASP Variables Typically in programming, a variable is used to store information and so it is in ASP. Two caveats are: –If the variable is declared outside a procedure it can be changed by any script in the ASP file. –If the variable is declared inside a procedure, it is created and destroyed every time the procedure is executed. To declare variables accessible to more than one ASP file, declare them as session variables or application variables. Session variables are used to store information about a single user, and are available to all pages in one application where an application is a collection of ASP pages.

10-9 ASP Procedures You can call a JavaScript procedure from a VBScript, and vice versa. When calling a VBScript or a JavaScript procedure from an ASP file written in VBScript, you can use the call keyword followed by the procedure name. <% Sub vbproc(num1,num2) Dim result result = num1 * num2 Response.Write(result) End sub %> 3 multiplied by 4 is:

10-10 Figure Using JavaScript and VBScript Functions in One ASP Page function jsproc(num1,num2) { var sum; sum = num1 + num2; Response.Write(sum); } Sub vbproc(num1,num2) Response.Write(num1*num2) End sub Using JavaScript Function: = Using VBScript Sub: 3 * 4 =

10-11 ASP Objects Most of the functionality you can build into an ASP page comes from objects on the server. These objects enable your pages to communicate effectively with the server, the application, the current session, and the user. In ASP, an object can have collections, properties, methods, and events. The Request and Response objects contain collections (bits of information that are accessed in the same way). Objects use methods to do some type of procedure and properties to store any of the object’s attributes (such as color, font, or size).

10-12 Uses for ASP Objects ASP objects are commonly used for chores such as: –Alerting users about relocated Web content by redirecting them using the ASP Redirect method to automatically redirect or route a browser to another Web page or Web site. –Monitoring user preferences and behavior by using ASP to place cookies to determine which part of the Web site a user is looking at and how long that user lingers on certain Web pages. –Obtaining user feedback by using the ASP Form and QueryString collections to gather user input from an HTML form. These collections simplify the creation Web sites that process user feedback, such as a departmental bulletin board, an online survey, or a data retrieval system.

10-13 ASP Objects (2) Five of the built-in ASP objects are commonly used for web application development: –Request Object –Response Object –Server Object –Session Object –Application Object

10-14 Request Object When a browser asks for a page from a server, it is called a request. The ASP Request object is used to get information from the user. The Request object contains all of the data sent to the web server when a browser makes a request. You can use the Request object to parse encoded URLs, access information from a form, and read cookies.

10-15 Figure Collecting the Name of the User First Name:

10-16 Figure Output of Welcome.asp

10-17 Figure Output of RevisedWelome.asp Welcome <% Response.Write(Request.Form("txtName")) %>

10-18 Figure Extracting Client’s and Server’s Environments Using Request.ServerVariables The requestor's browser environment is: <% Dim clientsEnv clientsEnv= Request.ServerVariables("HTTP_USER_AGENT") Response.Write(clientsEnv) Response.Write(" ") %> The server software is <% Dim serverEnv serverEnv=Request.ServerVariables("SERVER_SOFTWARE") Response.Write(serverEnv) %>

10-19 Figure Displaying the List of Members in the Request.ServerVariables Collection All possible server variables: <% For Each Item in Request.ServerVariables Response.Write(Item & " ") Next %>

10-20 Response Object The ASP Response object is used to send output to the user from the server. When a user clicks a hyperlink or types an http address into the web browser, the browser sends a request to the web server. The web server processes the request and the server Response object transmits a response back to the browser.

10-21 Server Object and Session Object The ASP Server object is used to access properties and methods on the server. The Session object is used to remember information about a user’s session. A session is the time a user spends at your site on a visit. It begins when a user opens any.asp page and continues as the user navigates from page to page in the site. Session variables are commonly used to track things like the contents of a user’s shopping basket, or a flag indicating that this user has been properly authenticated.

10-22 Application Object A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together. The purpose of the Application object is to store information that can be shared with all users of the application simultaneously. The Application object is used to store and access variables from any page, just like the Session object. The difference is that all users share one Application object, while with Sessions there is one Session object for each user.

10-23 ASP Cookies A cookie is a small file that the web server stores on the user’s computer to identify a user. Each time the same computer requests a page with a browser, it will send the cookie too. With ASP, you can both create and retrieve cookie values using the Response.Cookies collection. You can use cookies, as well as session and application variables, to store and retrieve information. You can set cookie values with the Response object: <% Response.Cookies("firstname")="Valda" %>

10-24 Figure Collecting Hobby Data From the User Please select a hobby Fishing Gardening

10-25 Figure Storing Cookie Data <% Dim strHobby Dim dteExpireDate strHobby= Request.Form("radHobby") dteExpireDate=DateAdd("d", 30, Now) ' adds 30 days ' You can use DateAdd("n", 10, Now) to add 10 minutes, ' or use DateAdd("m",1,Now) to add 1 month ' Write the cookie and set its expiration date Response.Cookies("HobbyCookie")=strHobby Response.Cookies("HobbyCookie").Expires = dteExpireDate %> Thank you for providing the information

10-26 Figure Redirection Based on the Cookie Data <% Dim strHobby strHobby = Request.Cookies("HobbyCookie") ' Retrieve the cookie ' Redirect the user to appropriate page Select Case strHobby Case "Fishing" Response.Redirect("Fishing.htm") Case "Gardening" Response.Redirect("Gardening.htm") Case Else Response.Redirect("AllProducts.htm") End Select %>

10-27 Figure Retrieving the Values of a Multi-Valued Cookie <% Dim x,y For each x in Request.Cookies If Request.Cookies(x).HasKeys Then Response.Write("Multiple values in the " & x & " cookie are: ") For Each y in Request.Cookies(x) Response.Write(" "& y & "=" & Request.Cookies(x)(y) & " ") Next Else Response.Write(x & " = " & Request.Cookies(x)) End If Response.Write " " Next %>

10-28 Figure The Output of ShowVisitCount.asp Number of visits since the server was started = <% Dim intCount intCount = Application("visitCount") Response.Write(" " & intCount) %>

10-29 Server-Side Includes The #INCLUDE directive lets you insert the content of another file into an ASP page before the server executes it. When ASP sees #INCLUDE, the contents of the file are placed into the ASP file in place of the #INCLUDE command. SSI is commonly used to store functions, headers, or any elements that will be reused on multiple pages. To insert a file into an.asp file, use the following syntax:

McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved The End