rutgers - active server pages

116
Active Server Pages: Web Scripting Made Easy A Hands-On Workshop in the New Brunswick Computing Services Instructional Lab By Michael Dobe Sponsored by The New Jersey Intercampus Network Internet Technology Project http://www.nji n.net

Upload: dr-michael-dobe-sr

Post on 17-Dec-2014

5.676 views

Category:

Education


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Rutgers - Active Server Pages

Active Server Pages:Web Scripting Made Easy

A Hands-On Workshop in the New Brunswick Computing Services Instructional Lab

By Michael Dobe

Sponsored by The New Jersey Intercampus NetworkInternet Technology Project

http://www.njin.net

Page 2: Rutgers - Active Server Pages

Workshop Overview

Fast paced five-part workshop designed to prepare you to create a truly dynamic site using Active Server Pages, VBScript, and Microsoft's IIS 4.0 Server on the Internet or on a college/university intranet.

Page 3: Rutgers - Active Server Pages

Workshop Goals

By the End of the Workshop You Will: Understand the concepts and components of Active Server

Pages

Know the steps to set up and configure development and production ASP Server environments

Learn the basics of ASP Scripting With VBScript

Manage states and events with application and session objects

Understand and use the bundled Active Server components

Connect to a MS Access database and display information

Know the steps to create your own ASP components

Page 4: Rutgers - Active Server Pages

Active Server Pages Workshop: About Your Instructor

6 Years Experience With Web Technologies in Higher Ed and Industry

Designed and Implemented Clio Web Project For Internet Web Hosting

at Rutgers Corporate Intranets for BMG Direct

Marketing and Warburg Dillon Read, LLC Currently Working As Web Architect for

Modem Media.Poppe Tyson.

See the Instructor’s Home Page at http://clioweb.net/mdobeFOR MORE INFO...

Page 5: Rutgers - Active Server Pages

About You and Your Classmates

Who Are Your Classmates?What Do Your Classmates Do With Computers?What Motivated You to Take This Course?What Do You Hope to Get Out of This

Workshop?

Page 6: Rutgers - Active Server Pages

“Active Server Pages”Administrative Information

Course Slides in Hard Copy and on the Web Prerequisites: Experience With HTML and Web

Server Technologies; some scripting experience desirable

Reference Book, Beginning Active Server Pages 2.0, is available from “brick and mortar” and online retailers

Workshop runs from 9:30-4:00 PMSee the NJIN Web Site at http://www.njin.net

FOR MORE INFO ...

Page 7: Rutgers - Active Server Pages

Demos and Hands-on Exercises: About The Systems

Will Use an NT Server (clio.rutgers.edu) and Workstations in the Classroom For this Workshop

Web Server Demos Using VNC (Virtual Network Computing)

Will Make Use of Web Browsers, MS-FrontPage 2000, MS Office 2000 and Visual InterDev 6.0

Workstation Configurations Will Allow You To Create and Modify FrontPage 2000 Webs on the Web Server and to Author ASP Pages

http://www.njin.net

Page 8: Rutgers - Active Server Pages

A Note on Remote NT Systems Management

Free Option: Virtual Network Computing Available from

http://www.uk.research.att.com/vnc/ Commercial Options:

pcANYWHERE Timbuktu

Using VNC, You Can Manage NT Server From a PC Workstation

Page 9: Rutgers - Active Server Pages

Active Server Pages: Part I

Topics: “Review of Client and Server-

Side Scripting”; “Getting Up and Running”; “Introducing ASP and VBScript”

Page 10: Rutgers - Active Server Pages

Part I Goals

Discuss client side/server side scripting

Introduce Active Server Pages (ASP)

Explain what platforms these scripts run on and which browsers can see the results

Discuss configuration of development and production ASP environments

Discuss the structure of an ASP page

Introduce VBScript, the default scripting language for ASP

Page 11: Rutgers - Active Server Pages

“Active Server Pages” 5 Parts at a Glance

Part 1: IntroductionPart 2: ASP Scripting in VBScript, Pt. IPart 3: ASP Scripting in VBScript, Pt.

IIPart 4: ASP ComponentsPart 5: ADO Components

Page 12: Rutgers - Active Server Pages

Client-Side and Server-Side Scripting: Your Web Development Options?

Code Must Reside on a ServerCode Can Be Executed

On a Server (Server-Side Scripts) In a Client Browser (Client-Side

Scripts)Client-Side Scripting Limitations?Reality: May Run a Mix of Code,

Some Intended For Client and Other For Server-Side Execution

Page 13: Rutgers - Active Server Pages

Benefits of Server-Side Scripting: Some Basic Things to Consider

Why Use Server-Side Scripts?Protection of Your Source Code:

People Can’t See the Source Code, Only the HTML the Server Returns to the Browser

Independence From Browser Specificity: Server-Side Scripts Work With Any Browser!

Page 14: Rutgers - Active Server Pages

Benefits of Server-Side Scripting: Some Basic Things to Consider

Why Use Active Server Pages Instead of CGI? Ease of Use? Speed?

OS PlatformASP Default Server-Side Scripting on IIS,

But CGI (and even Perl) work on NT ...

Page 15: Rutgers - Active Server Pages

ASP Definition

“Active Server Pages is an open, compile-free application environment in which you can combine HTML, scripts, and reusable ActiveX server components to create dynamic and powerful Web-based business solutions. Active Server Pages enables server side scripting for IIS with native support for both VBScript and Jscript.”

- Nancy Winnick Cluts (MSDN Web Workshop)

Page 16: Rutgers - Active Server Pages

ASP and The CGI Model

ASP = Active Server PagesAnother Form of Server-Side Scripting Like CGI, Can Be Used With Any

BrowserAlso Like CGI, Users See the HTML

Code and Not the Script Itself Unlike CGI, It Is Tied to the Microsoft

Platform ... Well, sort of ...

Page 17: Rutgers - Active Server Pages

Benefits of Using Active Server Pages

Customize Content on Per-Browser BasisUse Cookies to Customize Individual’s

Browsing ExperienceTight Integration With OS

Run as Service in NTTie-in To MS ACLs (Access Control Lists)

Support For ActiveX Server Components (Sever-Side Execution Eliminates Browser-Specificity)

Page 18: Rutgers - Active Server Pages

What You Need to Make ASP Work

ASP Supported By Default in IIS 4.0 Use NT Server With Internet Information

Server 4.0 For Production Web Environment For Development You Can Use Personal

Web Server for Win 95/98 and Peer Web Services for NT Workstation 4.0 (Both Called PWS)

Need PWS Version 4 For ASP! PWS Version Included With FP 98 Does

Not Support ASP!!!!!

Page 19: Rutgers - Active Server Pages

Steps to Enabling ASP Support

IIS 4 and PWS 4 Support ASP By Default Both Available for Free as Part of NT Server 4

Option Pack IIS Documentation Installs With Option Pack:

Chili!Soft Offers Extensions For Other Non-MS Operating Systems and Web Servers Available for Apache, Lotus, Netscape and O'Reilly,

running on Windows NT, Sun Solaris and IBM AIX http://www.chilisoft.com/

Page 20: Rutgers - Active Server Pages

Using ASP With IIS 4:A Review of MMC and ISM

URLs and IIS Directory StructureInternet Guest AccountWeb Publishing ServiceInternet Service Manager:

GUI Tools HTML Interface

Tools DemonstrationURLs and File Structure of IIS

Page 21: Rutgers - Active Server Pages

The Internet Guest Account

Installation Will Create the Internet Guest Account, Which is there to Allow Anonymous Access to Browse Your Site

The Internet Guest Account is called IUSER_computername (computername is your server’s NetBIOS name)

The Web Application Manager user account is IWAM_computername

Page 22: Rutgers - Active Server Pages

Microsoft Management Console (MMC) and the NT Service Manager

MMC Is an Interface to the NT Service: “Web Publishing Services”

Used to Manage the Hypertext Transfer Protocol Server (IIS) and Other TCP/IP Services

DEMONSTRATION OF ISM

• GUI Tool: MMC

• HTML Version

Page 23: Rutgers - Active Server Pages

Using ASP With PWS 4:The Administrative Interface

Review of Virtual Directories Permissions: Read, Execute, ScriptsVirtual Directory Mapping

Implementations on PWS 4 and IIS 4Creating Your Project Virtual Directory

Ready For Your First Server-Side

Script in ASP?

Page 24: Rutgers - Active Server Pages

Virtual Servers vs. Virtual Directories

Virtual Servers Are Separate Hostnames On the Same Physical Machine Bound to Different NICs (or Bound to Same NIC) Virtual Servers Have Their Own Separate Configs. Virtual Servers Appear to the Outside World as Separate Machines.

Virtual Directories Are Directories Which Appear Below the Root Directory in a Web Browser. May Be Located on the Same Physical Machine or on Another Machine. Virtual Directories Appear to the Outside World as Part of the Same Server. Why Would You Use a Virtual Server or a Virtual

Directory? Perhaps you would use a Virtual Directory for Active

Server Pages?

Page 25: Rutgers - Active Server Pages

Languages Used for ASP?

What Are ASP Pages Written In? VBScript JScript (JavaScript) PerlScript (ActiveState Tool Corp.)

ASP can integrate Java and ActiveX Technologies. Usually the Latter.

Page 26: Rutgers - Active Server Pages

Most Common Language: VBScript Defined

“Microsoft® Visual Basic® Scripting Edition, a subset of the Microsoft® Visual Basic® programming language, is a fast, portable, lightweight interpreter for use in World Wide Web browsers and other applications that use Microsoft® ActiveX® Controls, Automation servers, and Java applets.”

- Microsoft Script Technologies Site

Page 27: Rutgers - Active Server Pages

Ways to Write ASP Code:Your Choice of Editors

Any Test Editor: Notepad, vi (MKS Toolkit)

FrontPage 98 or 2000 98 Sometimes Alters Code Workaround is Available 2000 Support is More Robust

Visual InterDev 6.0 Part of Visual Studio Group Development Tool

Page 28: Rutgers - Active Server Pages

Using FrontPage 98

This Course Will Use FP98 as EditorTo Prevent FP 98 From Changing

Code:Using the FrontPage Editor Menu,

Select Insert | FrontPageComponent | InsertHTML

option to place

<!--webbot bot="HTMLMarkup" startspan --> and <!--webbot bot="HTMLMarkup" endspan -->

tags around your ASP code, so that is not modified by FrontPage.

Page 29: Rutgers - Active Server Pages

Structure of an ASP Page

ASP Script Code Mixed in Page With Regular HTML Code

2 Ways to Denote ASP Scripts <% Here is a Script %> <SCRIPT LANGUAGE=VBSCRIPT

RUNAT=SERVER>We Will Use the Former Convention

Page 30: Rutgers - Active Server Pages

<HTML><HEAD><TITLE>Polite Web Server</TITLE></HEAD><BODY BGCOLOR="wheat"><P><FONT COLOR="Teal" SIZE="3"><B>The Polite Web Server, at <%= Time %> on<%= Date %> </B></FONT></P><P><B> <% If Hour(Now) < 8 Then %> Don'tyou know what time it is? I was still inbed! <% ElseRandomizeintChoice = Int(Rnd * 4)Select Case intChoiceCase 0 %> So, where do you wantme to go today?<% Case 1 %> Well, look whose backvisiting us again...<% Case 2 %> Hi there, and welcometo our site.<% Case 3 %> It's raining here,what's the weather at your end like?<% End SelectEnd If %> </B></P><HR></BODY></HTML>

Page 31: Rutgers - Active Server Pages

In-Class Demo of Simple Script

The Simple “Punctual Web Server” Program (Example From Wrox.com)

Write Program in FP 2000Run Code on a Workstation Using

Personal Web ServerTest and Troubleshoot

Page 32: Rutgers - Active Server Pages

Active Server Pages: Part II

Topics: “HTML Forms” and “VBScript Basics: Variables, Variants, Operators, String Manipulation and Arrays”

Page 33: Rutgers - Active Server Pages

Goals For Part II

Review Use of Forms

Introduce ASP Basics: HTML Forms and Variables With VBScript

Download and Install Sample Code From Wrox.com

Work on Forms-based Examples

VBScript Variables in Depth

Strings and Arrays

Work on String Manipulation and Array Examples

Page 34: Rutgers - Active Server Pages

Review of HTML Forms

Pieces of the HTML Form (YourColor.html)

<FORM ACTION=“colors.asp" METHOD=post><P>Please Type Your Favorite Color Here:</P> <P><INPUT NAME="MyFavoriteColor" ></P><INPUT TYPE="submit" VALUE="Submit This Form"><P></P><P><INPUT TYPE="reset" VALUE="Reset This

Form"></P></FORM>

Page 35: Rutgers - Active Server Pages

Using Forms in FP 2000

By Default FrontPage 2000 Wants To Send Output To a Text File on the Server

Inserting Form Elements in the “Normal View” Inserts a FrontPage Bot, a.k.a. “FrontPage Component”

Best to Hand Code the HTML for the Forms in the “HTML View”

Page 36: Rutgers - Active Server Pages

Sample Form Code From FP 2000

<form method="POST" action="--WEBBOT-SELF--">

<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt"

S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->

<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>

Page 37: Rutgers - Active Server Pages

Using ASP Pages to Process User Input From HTML Forms

Sent Your Form Data to colors.asp, So Now We Need a file called colors.asp …

We gathered the Following Information From the User: MyFavoriteColor

We Need a Way to Do Something With MyFavoriteColor -- Enter VBScript Variables

Page 38: Rutgers - Active Server Pages

What are Variables?

“A variable is a section of memory that is allocated a name by the programmer. These sections of memory can be used to store pieces of information that will be used in the program. Think of variables as you might think of boxes. They're simply containers for information that you wish to store.” From Beginning Active Server Pages

Page 39: Rutgers - Active Server Pages

Using Variables in an ASP Page

Here is the Code for colors.asp:

<HTML><H1> So Your Favorite Color is<% Dim strFavColorstrFavColor=Request.Form("MyFavoriteColor

")Response.Write strFavColor%> !</H1></HTML>

Page 40: Rutgers - Active Server Pages

Another Example of Form Input: The Need to Normalize Data

Use of Drop Down Menu to Give User Choices For Data Entry/Selection

Form Tags are <FORM ACTION=choosing.asp METHOD=POST> <SELECT name= choice><OPTION selected>First Choice<OPTION><OPTION>Second Choice</OPITON></SELECT></FORM>

Need to Send This to script.asp for processing …

Page 41: Rutgers - Active Server Pages

Creating the ASP Page To Handle Drop-Down Menu Items

choosing.asp contains the following code:Option Explicit

<%

Dim strChoice

strChoice = Request.Form(“choice")

Response.Write strChoice

%>

This will print the choice your user made on the drop-down menu page

Page 42: Rutgers - Active Server Pages

Hands-On Exercise 1:Download and Install Sample Code

Download and Install Examples From Wrox.com Site

Access Zipped Archive of All Code From Beginning Active Server Pages

Direct URL is:http://www.wrox.com/Store/Download.asp?Code=1347

Page 43: Rutgers - Active Server Pages

Hands-On Exercise 2: Forms and ASP

View Samples From Chapter 3 Forms:

Department Affiliation Form Get Jacket Information Form

Corresponding ASP CodeRegistration of Department ReplyJacket Order Confirmation

Modify the Above Code to Normalize the Data With Drop-Down Menus

Page 44: Rutgers - Active Server Pages

Naming Variables in VBScript

Limit is 255 characters All variable names must begin with

an alphabetical characterVariable names must not contain an

embedded period/full-stopVBScript is not case-sensitive!

(Remember that JScript/JavaScript is case sensitive)

Page 45: Rutgers - Active Server Pages

VBScript Variables and Variants

Most programming languages allow you to declare data types for your variables

VBScript has only one type, called the variant

Variants come in a number of different subtypes: numeric, string, date, boolean and special (empty, NULL and object)

Page 46: Rutgers - Active Server Pages

Use of Operators in VBScript

Assignment ComparisonLogicalArithmeticConcatenati

ng

Page 47: Rutgers - Active Server Pages

String Manipulation in VBScript

LenLeftRightMidInStrLtrim, Rtrim and Trim

Page 48: Rutgers - Active Server Pages

Arrays in VBScript

The Purpose of ArraysArray Declaration

Dim StudentsInClass(7)Array Redeclaration

Redim StudentsInClass(8)Redim Preserve StudentsInClass(8)

Mulit-Dimensional Arrays

Page 49: Rutgers - Active Server Pages

Hands-On Exercise 3: Strings and Arrays in VBScript

Examples From Chapter 4 Using a TypeName to Return a Variant

SubtypeUsing Variants to Perform a CalculationConverting a Variant ExampleString Manipulation ExampleCreating Local Variables ExampleSetting Up an Array Example

Page 50: Rutgers - Active Server Pages

What We Accomplished This Morning in Part I

Introduced the Course Discussed client side/server side scripting Introduced Active Server Pages (ASP) Explained what platforms these scripts run on and

which browsers can see the results Discussed configuration of development and

production ASP environments Discussed the structure of an ASP page Introduced VBScript, the default scripting language for

ASP

Page 51: Rutgers - Active Server Pages

What We Accomplished This Morning in Part II

Reviewed Use of Forms

Introduced ASP Basics: HTML Forms and Variables With VBScript

Downloaded and Installed Sample Code From Wrox.com

Worked on Forms-based Examples

Discussed VBScript Variables in Depth

Discussed Strings and Arrays

Worked on String Manipulation/Array Examples

Page 52: Rutgers - Active Server Pages

Reference Materials in Parts I & II

Beginning Active Server Pages 2.0 Chapter 1 “Getting Started With ASP” and Chapter 2 “Client-Side Scripting and Server-

Side Scripting” Chapter 3 “Basic ASP Techniques” Chapter 4 “ASP Variables” Chapter 5 “Control Constructs”

Microsoft’s Scripting Technologies Sitehttp://msdn.microsoft.com/scripting/VBScript Resources at This Site

Page 53: Rutgers - Active Server Pages

ASP Docs on Your IIS Server:http://your_server/iishelp/iis/misc/default.asp

Scripter’s ReferenceObject, Global, Component and Programmer’s Refs

Activeserverpages.com http://www.activeserverpages.com

MSDN Web Workshop Formerly “Site Builder Workshop”

http://msdn.microsoft.com/workshop/ Select: Server Technologies/Active Server Pages

Reference Materials Used in Parts I & II (Cont.)

Page 54: Rutgers - Active Server Pages

Lunch Break

Take 45 Minutes to Eat!

Page 55: Rutgers - Active Server Pages

Active Server Pages: Part III

Topics: “Flow Control in VBScript” “ASP Objects” and “The Visual InterDev 6.0 IDE”

Page 56: Rutgers - Active Server Pages

Discuss Flow Control in VBScriptWork on Flow Control Examples With

VBScript and ASPDiscuss the ASP Object ModelWork on Object Examples With ASP Object

Model Introduce Visual InterDev 6.0 Integrated

Development Environment

Goals For Part III

Page 57: Rutgers - Active Server Pages

What We Covered Right Before Lunch

Reviewed Use of Forms

Introduced ASP Basics: HTML Forms and Variables With VBScript

Downloaded and Installed Sample Code From Wrox.com

Worked on Forms-based Examples

Discussed VBScript Variables in Depth

Discussed Strings and Arrays

Worked on String Manipulation/Array Examples

Page 58: Rutgers - Active Server Pages

What is Flow Control?Action vs. Control Statements

“Action statements: Statements that perform an activity, such as the creation of a part of a page, a change to a variable, a redirection to another page, or changing a setting on the server.

Control statements: Statements that give ASP instructions on which statements to execute, and in what order” From Beginning Active Server Pages

Page 59: Rutgers - Active Server Pages

Types of Control Structures

Branching If … Then Select … Case

Looping For … Next For Each … Next Do While

Page 60: Rutgers - Active Server Pages

If … Then … Else

Used to select one of two sets of lines to execute.

Also used for complicated comparisons, such as expressions using the terms and, or, not.

Part of If Then Else: An expression: that is, a test that gives a true or false answer; An "if true" section of code; An "if false" section of code; An ending statement

Page 61: Rutgers - Active Server Pages

Flow Control Walkthrough 1:TioIfThenOneForm.asp

1. <HTML>2. <HEAD>3. <TITLE>Spring Retreat Form</TITLE>4. </HEAD>5. <BODY>6. <H1>Corporate Retreat Registration</H1>7. <H3>To get the logistics information 8. for your meeting please answer these two questions.</H3>9. <FORM ACTION="TioIfThenOneResponse.asp" METHOD="post">10. Please type your preference in month, either March or April:<BR>11. <INPUT TYPE="text" NAME="MonthPref"><P>12. Please type your preference in location, either East or West:<BR>13. <INPUT TYPE="text" NAME="Location">14. <BR><BR>15. <INPUT TYPE="submit"> <INPUT TYPE="reset"> 16. </BODY>17. </HTML>

Page 62: Rutgers - Active Server Pages

Flow Control Walkthrough 1 Cont.:TioIfThenOneForm.asp

1. <HTML>2. <HEAD>3. <TITLE>Spring Retreat Response</TITLE>4. </HEAD>5. <BODY>6. <%7. varMonthPref = Request.Form("MonthPref")8. varLocation = Request.Form("location")9. Response.Write "<H1>Corporate Retreat Registration

<BR>Your Details</H1>"10. If varMonthPref="March" Then11. Response.Write "Your meeting will be held on

March 15th "12. Else13. Response.Write "Your meeting will be held on April

16th "14. End If15. If varLocation="East" Then16. Response.Write "in Myerstown, Pennsylvania"17. Else18. Response.Write "in Malibu, California"19. End If20. %>21. </BODY>22. </HTML>

Page 63: Rutgers - Active Server Pages

Select … Case

Used anytime you need to make a choice among several answers (more than just True and False) then use Select Case.

The syntax for Select Case has four parts: State which variable to test; State a possible answer and what to do if that answer is correct; Repeat for as many possible answers as you want to handle; End the Select Case control structure

Page 64: Rutgers - Active Server Pages

Flow Control Walkthrough 2:TioSelectOneForm.asp

1. <HTML>2. <HEAD>3. <TITLE>Spring Retreat Form</TITLE>4. </HEAD>5. <BODY>6. <H1>Corporate Retreat Registration</H1>7. <H3>To get the logistics information 8. for your meeting please answer these two questions.</H3>9. <FORM ACTION="TIOSelectOneResponse.asp" METHOD="post">10. Please type your preference in month, either March or April:<BR>11. <INPUT TYPE="text" NAME="MonthPref"><P>12. Please type your preference in location, either East or West:<BR>13. <INPUT TYPE="text" NAME="Location">14. <BR><BR>15. <INPUT TYPE="submit"> 16. <INPUT TYPE="reset"> 17. </BODY>18. </HTML>

Page 65: Rutgers - Active Server Pages

Flow Control Walkthrough 2 Cont.:

TioSelectOneResponse.asp 1. <HTML>2. <HEAD>3. <TITLE>Corporate Retreat Response</TITLE>4. </HEAD>5. <BODY>6. <%7. varMonthPref = Request.Form("MonthPref")8. varLocation = Request.Form("Location")9. Response.Write "<H1>Corporate Retreat Registration <BR> Your

Details</H1>"10. Select Case varMonthPref11. Case "march"12. Response.Write "Your meeting will be held on March

15th "13. Case "March"14. Response.Write "Your meeting will be held on March

15th "15. Case "april"16. Response.Write "Your meeting will be held on April

16th "17. Case "April"18. Response.Write "Your meeting will be held on April

16th "19. End Select20. If varLocation="East" then21. Response.Write "in Myerstown, Pennsylvania"22. Else23. Response.Write "in Malibu, California"24. End If25. %>26. </BODY>27. </HTML>

Page 66: Rutgers - Active Server Pages

Types of Looping Statements:For…Next; For … Each … Next; Do …While

“ForNext is used to repeat line(s) when, at the beginning of therepetitions, we know exactly how many repetitions we want. Forexample, if we know there are five reviewers we could repeatfive times the set of steps that adds and formats a comment form.”ForEachNext is used to repeat line(s) one time for each item in acollection. For example, if there are 6 items in a collection, thenthe lines will be executed 6 times. The difference between thisand ForNext is that you don’t have to know how many itemsthere are when you write it.”DoWhile is used to repeat line(s) when we don't know how manyrepetitions we want. DoWhile will repeat lines as long as aspecified condition is true.”

From Beginning Active Server Pages

Page 67: Rutgers - Active Server Pages

Flow Control Walkthrough 3:TioForNextOneForm.asp

1. <HTML>2. <HEAD>3. <TITLE>TIO For Next One Form</TITLE>4. </HEAD>5. <BODY>6. <H2>Weekly Client Contacts</H2><BR>7. <FORM ACTION=TioForNextOneResponse.asp METHOD =

post>8. <P>Please enter the first day of the week in the form

mm/dd/yy such as9. 09/20/98 <BR>10. <INPUT TYPE=text NAME="start">11. <P>Please enter the last day of the week in the same

form<BR>12. <INPUT TYPE=text NAME="end"><BR>13. <INPUT TYPE=submit>14. <INPUT TYPE=reset>15. </BODY>16. </HTML>

Page 68: Rutgers - Active Server Pages

Flow Control Walkthrough 3 Cont.:

TioSelectOneResponse.asp 1. <HTML>2. <HEAD>3. <TITLE>TIO ForNext One Response</TITLE>4. </HEAD>5. <BODY>6. <H2>Weekly Client Contacts for George

Washington</H2><BR>7. <%8. varStart=Request.Form("start")9. varEnd=Request.Form("end")10. varStart = cdate(varStart)11. varEnd = cdate(varEnd)12. varNumberDays=(varEnd-varStart)13. For varLineCounter = 0 to varNumberDays14. Response.Write "Clients: ___________________"15. Response.Write "<BR ><BR><BR>"16. Next17. %>18. signed _________________________19. George Washington20. </BODY>21. </HTML>

Page 69: Rutgers - Active Server Pages

Hands on Flow Controls

Modify the TioIfThenOne set of examples to Make the Event Occur in the Winter

Modify the TioSelectOne set of examples to Make the Event Occur in the Winter

Try TioForNextOneForm.asp andTioForNextOneResponse.asp as a Winter Event!Modify the TioForNextOne set of examples to

Make This an Attendance Report for This Class

Page 70: Rutgers - Active Server Pages

Write One Time, Run Many Times: Code Reuse in ASP

Within A Single ASP Page, May Need to Insert Some Code in a Number of Places

May Have the Need to Have Code Do Something and then Give the Results to another Part of the Page For Processing

Enter Procedures: Subs and Functions

Page 71: Rutgers - Active Server Pages

What Are ASP Procedures?

“Subprocedures carry out an action: for example, a Sub would be used to carry out the actions of putting text onto a page

Functions carry out action statements and return an answer to your code: a function would be used to calculate a delivery date and return that answer to your main program” From Beginning Active Server Pages

Page 72: Rutgers - Active Server Pages

Creating a Sub

3 Parts of a Procedure1. The procedure’s name2. The code that the procedure should

execute3. An ending statement. In addition you will have to direct your

main body of code to actually run the procedure.

Page 73: Rutgers - Active Server Pages

<HTML><HEAD><TITLE>Example Procedures Two</TITLE></HEAD><BODY><%varRegion=Request.Form("region")Sub SalesContactInfo(region)Response.Write "Price quotes for this productare available from "Select Case RegionCase "North"Response.Write "Brian at 201/555-1212."Case "South"Response.Write "Rob at 719/555-1212."Case "East"Response.Write "Pat at 604/555-1212."Case "West"Response.Write "John at 312/555-1212."End SelectEnd Sub%><H2 align="center">On-Line Clothier<BR>New Items for September, 1998</H2><H3>Sweaters</H3><P>New selections of warm and woolly AutumnSweaters<SMALL>.</SMALL> Special line of&nbsp; colors for fall festivities includingBlack/Orange and our new Autumn Medley.<%call SalesContactInfo(varRegion)%><H3>Vests</H3><P>Get ready to dance around the MayPole in thisseason's brightest selection of FloweredVests. We're in swing with the retro look featuringflowers from the 50's, 60's and 70's.<%call SalesContactInfo(varRegion)%><H3>Ties</H3><P>No reason to look uncomfortable just because youare wearing a noose! We have a newline of ElastoTies<EM>&#153;</EM> with lots ofbungee in the middle to allow you to <EM>Expandunder Pressure</EM><SMALL>®</SMALL>.<%call SalesContactInfo(varRegion)%></BODY>

ASP Subprocedure Example:SubExample.asp

Page 74: Rutgers - Active Server Pages

ASP Function Example:TioFunctionForm.asp

1. <HTML>2. <HEAD>3. <TITLE>TIO Function Form</TITLE>4. </HEAD>5. <BODY>6. <H2>Cost Calculator for<BR>7. Attendance at Corporate Conference</H2>8. Please provide the following information so we can estimate

your9. local costs while attending the conference10. <FORM ACTION="TioFunctionResponse.asp" METHOD=post>11. Please type your preference in location, either city or suburb:12. <INPUT TYPE=text NAME="location"><BR>13. <INPUT TYPE=submit>14. <INPUT TYPE=reset>15. </BODY>16. </HTML>

Page 75: Rutgers - Active Server Pages

<HTML><HEAD><TITLE>TIO Function Response</TITLE></HEAD><BODY><%Function CityCost(NumberDays)varHotelTotal = NumberDays*175varMealsTotal = NumberDays*75varAirportTransport = 85CityCost = varHotelTotal+varMealsTotal+varAirportTransportEnd Function

Function SuburbCost(NumberDays)varHotelTotal = NumberDays*85varCarTotal = NumberDays*45varMealsTotal = NumberDays*75SuburbCost = varHotelTotal+varMealsTotalEnd Function

varLocation=Request.Form("location")%><H3>Your have chosen the hotel in the <%=varlocation%>.<BR>your estimated costs for this seminar will be:</H3><%Select Case varLocationcase "city","City","CITY"

varCost = CityCost(2)Response.Write "The two day course will cost

$" & varCost & "<br>" varCost = CityCost(4)Response.Write "The four day course will cost

$" & varCost & "<br>"varCost = CityCost(6)Response.Write "The six day course will cost

$" & varCost & "<br>"case "suburb","Suburb","SUBURB"

varCost = SuburbCost(2)Response.Write "The two day course will cost

$" & varCost & "<br>"varCost = SuburbCost(4)Response.Write "The four day course will cost

$" & varCost & "<br>"varCost = SuburbCost(6)Response.Write "The six day course will cost

$" & varCost & "<br>"case else

Response.Write "error"end select%></BODY>

ASP Function Example:TioFunctionResponse.asp

Page 76: Rutgers - Active Server Pages

Use of Objects in ASP

ObjectsMethodsPropertiesEventsEncapsulationThe Object

Model

Page 77: Rutgers - Active Server Pages

About Visual InterDev 6.0

Microsoft’s Integrated Development Environment for Web Development

Microsoft’s Suggested Development Environment for Active Server Pages

Part of Visual Studio 6.0 or Stand-Alone Professional Version

Tight Integration With FrontPage For Design and Content Management

Works With FP 2000 Server Extensions for Remote Management of Coding Projects

Page 78: Rutgers - Active Server Pages

Visual InterDev 6.0 Walkthrough

Setting Up and Configuring the Client and Server Environments

The Concept of “Projects” (Like FP “Webs”) “Project Management”: Developing in Master and

Local Modes (Working Copies) The Authoring Environment, Like FP Editor

Three Views: Design, Source, Quick View Highlight on Source View: Color Coding and Pull Right

Options Development Environment: Toolbox, Project Explorer,

Task List

Page 79: Rutgers - Active Server Pages

Getting Visual InterDev 6.0

Trial Version Available for Download (Times Out)

InterDev 6.0 is Part of Visual Studio 6.0 InterDev 6.0 Stand Alone Professional

Version Available at Academic Price: $99 Pro Version Consists of the Following:

Server Tools: Part of Option Pack Client Tools: Authoring Environment and Limited

Source Control Manual Also Comes With NT Workstation Bundled!

Page 80: Rutgers - Active Server Pages

Class Break

Take 15 Minutes to Stretch!

Page 81: Rutgers - Active Server Pages

Active Server Pages: Part IV

Topics: “The ASP Object Model in Depth” and “ASP Components”

Page 82: Rutgers - Active Server Pages

Review Object-Oriented Programming Concepts and Explain the ASP Object Model

Discuss ASP Request and Response Objects

Discuss ASP Application and Session Objects

Work on Object Examples With VBScript and ASP, Both As Walkthroughs and as Hands-on Exercises

Discuss ASP Components

Work on ASP Components Examples, Both As Walkthroughs and as Hands-on Exercises

Goals For Part IV

Page 83: Rutgers - Active Server Pages

Object-Oriented Programming

Some Key Terms Instance Properties Methods Events

Key Questions: What is Encapsulation? What are Synchronous and Asynchronous

Events?

Page 84: Rutgers - Active Server Pages

The ASP Object Model: Three Levels

Page Level Objects Request Response

Application Level Objects Application Session

Server Object: ComponentsCh. 6 Walkthrough ASPs Using

MyTelephone.exe Program

Page 85: Rutgers - Active Server Pages

Page-Level Objects:The Request Object

Collections QueryString Form ServerVariables (role of browscap.ini file) Cookies ClientCertificate

Properties and Methods: TotalBytes Property and BinaryRead Method

Ch. 7 Walkthrough of RequestForm.asp (Put), RequestQuery.asp (Get), browser-os.asp and ServVars.asp

Page 86: Rutgers - Active Server Pages

Page-Level Objects:The Response Object

Write and Redirect MethodsThe Response.write ShortcutBuffer Property: The Role of the Output BufferFlush, Clear and End Methods2 More Properties for the Response Object:

Expires and ExpiresAbsoluteCh. 8 Walkthroughs for Buffer Control,

Browser Redirection (BufferOutput.asp;PageChoice.html, choosePage.asp, Page1.html and Page2.html)

Page 87: Rutgers - Active Server Pages

Application-Level Objects:The Application Object

Challenge of Maintaining StateVirtual Directories Considered ApplicationsRole of the global.asa fileScope – Application vs. SessionApplication Object Collections: Contents

and StaticObjectsUsing the Lock and Unlock MethodsChapter 9 Walkthrough for creation of a

global.asa file (p. 262 and 267)

Page 88: Rutgers - Active Server Pages

Application-Level Objects:global.asa in Detail

Event Handling Subroutines: Application_OnStart Application_OnEnd Session_OnStart Session_OnEnd

Page 89: Rutgers - Active Server Pages

Application-Level Objects:The Session Object

Defining a SessionWhy would this be “the most

powerful object in Active Server Pages”?

Session Shortcut Annotation (p. 272)Collections: Contents and

StaticObjects

Page 90: Rutgers - Active Server Pages

Application-Level Objects:The Session Object (Cont)

• Session Object Properties include:– SessionID (careful not to use w/db apps.)– Timout (Need to test for ave. user time)– CodePage and LCID

• Session Object Methods: Abandon• Walkthrough Chapter 9 Exercise

SessionVarTest.asp (See pp. 275-278)

• Using global.asa

Page 91: Rutgers - Active Server Pages

Using Cookies in ASP

Difference Between Session-Level Variables and Cookies?

Period of Persistence: Set the DateWalkthrough the Using ASP Cookies

Example From Chapter 9 (see pp 286-292)

Page 92: Rutgers - Active Server Pages

Hands-On Exercise:Working With Page and Application-Level Objects

Exercise Files For Work With ASP Objects Taken From Chapters 6-9 in Beginning Active Server Pages 2.0

Run the Chapter 8 Exercise that Combines the Request and Response Objects: FormExample.html and FormExample.asp (For Text Reference See pp. 248-257)

Run the Chapter 9 Exercise That Does Visitor Tracking: Create global.asa and VisitorCount.asp (For Text Reference see pp 280-4)

Page 93: Rutgers - Active Server Pages

ASP Components and Sever Objects

ASP Components are Server-Level Objects That are Instantiated in Your Code in Order For You to Access Them

Syntax is as follows:<%Set objInstanceName =

Server.CreateObject(“ClassName.ComponentName”)

%>

Page 94: Rutgers - Active Server Pages

Default Components Using Visual InterDev 6.0

Drag and Drop ObjectsLocation: In Toolbox, Under Server ObjectsSome Server Objects/Components

Included: Ad Rotator Browser Capabilities Content Linking Script Objects: Dictionary and Filesystem

Objects

Page 95: Rutgers - Active Server Pages

Hands-On Exercises:Trying Out ASP Components

Exercise Files For This Part’s Work With ASP Components Taken From Chapter 12 in Beginning Active Server Pages 2.0

Work With Ad Rotator and Content LinkerA Word on the Browser Capabilities

Component and Try the Browser Capabilities Component and Use it in Your Own Page to Test It’s Functionality

Page 96: Rutgers - Active Server Pages

Active Server Pages: Part V

Topics: “ASP Scripting Objects” “Debugging” and “ASP Data Store Connectivity Using ADO Components”

Page 97: Rutgers - Active Server Pages

Goals For Part V

Finish Coverage of Built-in ASP Component Examples

Briefly Cover the ASP Scripting Objects

Discuss Debugging Using Simple Text Editor, MS Script Debugger and Visual InterDev 6.0

Review ODBC and OLE-DB Data Source Basics

Discuss ASP ActiveX Data Objects (ADO)

Work on ADO Examples: Connect To MS Access Database Using ADO

Discuss Issues in Scaling to MS SQL Server: How to Begin Planning a Smooth Upgrade Path

Where Do We Go Now?

Page 98: Rutgers - Active Server Pages

Trying Out ASP Components

Exercise Files From Part IV Work With ASP Components Taken From Chapter 12 in Beginning Active Server Pages 2.0

Work With Ad Rotator and Content LinkerA Word on the Browser Capabilities

ComponentTry the Browser Capabilities Component

and Use it in Your Own Page to Test It’s Functionality

Page 99: Rutgers - Active Server Pages

ASP Scripting Objects

Dictionary Object Allows You To Store Keyed Values

FileSystemObject and FileSystemObject Collections: Manipulate Views of File System, etc.

Server-Side Include (SSI) Object Lets You Reuse the Code You Write

TextStream: A Particularly Useful Example in the “ASP Source Code Viewer,” a.k.a. DisplaySource.asp (pp. 356 Have a Look!)

Page 100: Rutgers - Active Server Pages

Basic Debugging Tips: Using A Text Editor and a Browser

Use Option Explicit to Force Variable Declaration

Code Re-usageClient vs. Server-Side DebuggingDon’t Be Obscure When Naming

VariablesComment Your Code and Then

Comment Your Code Some More …

Page 101: Rutgers - Active Server Pages

Debugging Under Win 32:MS Script Debugger & VI 6.0

Dearth of Robust Debugging Tools.Yet, Script Debugger Does Offer Some

Conveniences: Call Stack, Running Documents and Command

Windows all Appear Cascaded (See pp. 387) Running Documents Window Separates IE and

ASP-Based Scripts (Client and Server-Side Differentiated For You)

Visual InterDev Allows for Remote Host Debugging, So You Can Debug Right on the Server

Page 102: Rutgers - Active Server Pages

What and How You Connect:Data Stores and Connections

Database as subset of Data Store.Connection Links ASP Page to the

Data StoreData Source Name (DSN) is a Named

Connection to a Data StoreGenerated Through the Microsoft

ODBC Data Source Administrator

Page 103: Rutgers - Active Server Pages

The ODBC Data Source Administrator

Page 104: Rutgers - Active Server Pages

Setting Up ODBC Access: 4 Steps to Creating a DSN

Step 1: Select ODBC From the Control PanelStep 2: Select Add From the System DSN

PanelStep 3: Select MS Access From the List of

Drivers on the Create New Database Source Panel and then Click on the Finish Button

Step 4: Type in a Data Source Name and Description, Select the Database and then Click on the ok button

Page 105: Rutgers - Active Server Pages

Adding a Data Source Name (DSN)

STEP 1

STEP 2

STEP 3STEP 4

Page 106: Rutgers - Active Server Pages

Using the DSN in ASP Code

DSN Resides on the Server Where the ASP Code Runs (Implications For Develop Locally/Serve Centrally)

Example of Simple DSN Usage Using Contact.mdb and Contact.asp from the Wrox Site (pp. 404-5)

Behind the Scenes: OLE-DB communicates with ODBC Drivers, Adds a Layer Between ActiveX and the Data Store

Page 107: Rutgers - Active Server Pages

ActiveX Data Object Component

ADO is the “friendly face of OLE-DB”Superset of DAO (Data Access

Objects) and RDO (Remote Data Objects)

Using ADO Can Use DSN-Less Connection Strings, Which Allows You to Use an SSI (pp.409-411)

Page 108: Rutgers - Active Server Pages

What We Accomplished This Afternoon in Part III

Reviewed Pre-Lunch Discussion

Discussed Flow Control in VBScript

Worked on Flow Control Examples With VBScript and ASP

Discussed the ASP Object Model

Worked on Object Examples With ASP Object Model

Introduced Visual InterDev 6.0 Integrated Development Environment

Page 109: Rutgers - Active Server Pages

Reviewed Object-Oriented Programming Concepts and Explain the ASP Object Model

Discussed ASP Request and Response Objects

Discussed ASP Application and Session Objects

Worked on Object Examples With VBScript and ASP, Both As Walkthroughs and as Hands-on Exercises

Discussed ASP Components

Worked on ASP Components Examples, , Both As Walkthroughs and as Hands-on Exercises

What We Accomplished This Afternoon in Part IV

Page 110: Rutgers - Active Server Pages

Finished Coverage of Built-in ASP Component Examples

Briefly Covered the ASP Scripting Objects

Discussed Debugging Using Simple Text Editor, MS Script Debugger and Visual InterDev 6.0

Reviewed ODBC and OLE-DB Data Source Basics

Discussed ASP ActiveX Data Objects (ADO)

Worked on ADO Examples: Connect To MS Access Database Using ADO

Discussed Issues in Scaling to MS SQL Server: How to Begin Planning a Smooth Upgrade Path

Next … Where Do We Go Now?

What We Accomplished This Afternoon in Part V

Page 111: Rutgers - Active Server Pages

Where Do We Go From Here?

Read Beginning Active Server Pages 2.0

Consider More SQL ReadingsForge Ahead With the Wrox Press

Books!

Page 112: Rutgers - Active Server Pages

Beginning Active Server Pages 2.0 Chapter 6 “Objects, Properties, Methods and

Events” Chapter 7 “The Request Object” Chapter 8 “The Response Object”

Microsoft’s Public NNTP Server: msnews.microsoft.com Also available through DejaNews and Talkway Browse the microsoft.public hierarchy for

scripting, ASP and IIS discussion groups

Reference Materials Used in Part III

Page 113: Rutgers - Active Server Pages

Beginning Active Server Pages 2.0 Read Chapter 9 “Applications, Sessions and Cookies” Read Chapter 10 “Active Server Pages Components” Skim Chapter 11 “The Scripting Objects” Skim Chapter 12 “Debugging ASP” Carefully Read Chapter 13 “Databases With ASP”

Cyscape, Inc. Site For the Latest on browscap.ini: http://www.cyscape.com/browscap/

Reference Materials Used in Parts IV and V

Page 114: Rutgers - Active Server Pages

Web Development Resources Indexes

Yahoohttp://dir.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/

Netscape DevEdgehttp://developer.netscape.com/

Sun’s JavaSofthttp://java.sun.com

Microsoft’s Developer Networkhttp://www.microsoft.com/sitebuilder/

http://www.njin.net

Page 115: Rutgers - Active Server Pages

What We Accomplished Today

Reviewed MS FrontPage 2000’s Basic Features and Began to Utilize it as a development environment for advanced Web design.

Learned practical skills to enhance your institutions' Web sites.

Learned about ODBC connectivity for dynamic database driven web sites

Learned about Visual InterDev.

http://www.njin.net

Page 116: Rutgers - Active Server Pages

For Further Information

See the Seminar Site at:http://www.clioweb.net/mdobe/teaching/1999/NJIN-ITP/

Feel Free to Contact the Instructor E-mail: [email protected]

http://www.njin.net