asp technology

Post on 18-Dec-2014

733 Views

Category:

Business

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Active Server Page

A. Barletta

Active server pages is a 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

What is ASP ?

z New technology for Web Server (Windows platform)z Browser independence: ASP can run complex page

building logic on the server and send only results to the client

z Database constructed pages that allow viewing, updating and additions to server databases

z New approach to creating complex web pages that can draw on databases or other server objects

z Easy to use components running on the server (not on the client)

What is ASP ?

z Built in and 3rd party components that require no browser scripting ability, yet accomplish complex tasks that are difficult with browser scripting(ActiveX)

z Native support for VBScript and Jscript™z Your own components with C++, Visual Basic or Java,

as a result you can build your own or buy one of hundreds of pre-built ASP components cheap to save your programming time

z Technology provides a compile-free environment z Creating server applications using any combination of

HTML, scripting, and components

What is ASP ?

z An alternative way to CGI programs for Windows platform (IIS 3.0 and above)

z component of an ASP-based application run on the same process as IIS 3.0 y greatest efficiency y ASP is integrated with the operating system and web

server y communicate each other internally with COMy externally with DCOM

z Overall !!!! Saves time and money in development, testing, deployment, and maintenance of Internet and Intranet web sites !!!!

ASP Architecture

Internet Information

Server IIS 3.0

ActiveX Server Scripting (VBscript,

JScript, Perl)

COM

ActiveX ServerComponents

ODBC Database

ASP files

WEB server

HTTP

WEB Clients

Es:NT 4.0/IIS 3.0

CGI Architecture

WEB Server(Apache)

CGI apps(Perl, C, C++)

CGI files

DB files

HTTP

WEB Clients

Es:Linux/Apache

«Script» Architecture (pure)

WEB Server

HTML + Script files

WEB Clients

Script compiler (JScript)

Virtual Machine (Java)

HTTP

Requirements

z IIS 3.0 or above & WinNT 4.0 serverz Peer Web Services on WinNT 4.0 workstationz Personal Web Services on Windows 95

ASP: How it works

Scripting Engine

ActiveX Component

Intranet & Internet

ASP

asp file

IIS

Pc

Mac

Workstation

Scripting and ASP

z ASP provides a server-side scripting environment (VBScript, Jscript, Perl, ActiveX, etc)

z dynamic and interactive pagesz gives nevertheless the possibility to insert client

side scripting (VBScript, Jscript, Java, ActiveX, etc)z Scripting languages are an intermediate stage

between HTML and programming languagesy HTML : static format languagey C, C++, VB, Java: dynamic programming languages

z customizing HTML pagesz supports any ActiveX scripting languages

Client Server

Client and Server scripting in Web pages

z With ASP you can balance client and server side scripting and features

z You can incorporate both server and client scripting in a single .asp file

z Three tier architecture more stable and balancedz Respond to different target application,

languages and browserz Flexibilityz Security features

Server scripting

z HTML pages on the fly on the server and sent pure HTML page to the browser (dynamic)

z independent from browser: all kind of browser client ! (HTML only is sent)

z all server scripting take place before the page is sentz complex database query mechanisms on DB systems

by the Web server (ODBC)y filtering & record modification

z develop for internet ! (We don’t know user browser)

Client scripting

z Pages more interactivez Less band usage (less traffic on the net for simple

control; ie: validate data entry fields)z Dipendent on the browser and scripting

implementation (Jscript, JVM, etc)z Specialized for intranet application (We know user

browser !)

Tagging scriptCLIENT

<SCRIPT LANGUAGE =“FavoriteScript”>

<!--your code---></SCRIPT>

z Any time you want to insert your code

SERVER<%LANGUAGE

=“FavoriteLanguage”%>z Once at the beginning<% your code %>or<SCRIPT LANGUAGE =

“FavoriteLanguage”RUNAT = “SERVER”>

your code</SCRIPT>or<!--#includesvirtual="ASPTips/adovbs.asp"-->z Any time you insert your code

Build-in object (intrinsic)

z ASP includes 5 standard server and application objects for global usey Request to get information from usery Response to send information to the usery Server to control the Internet Information Servery Session to store information about and change settings

for the user’s current Web-server sessiony Application to share application-level information and

control settings for the lifetime of the application

Build-in object

z Request and Response objects contain collectionsz Objects use ...

y methods to do some type of procedurey properties to store any of the object’s attributes (such

color, font, attributes)

Request object

z The request object is used to get information from the user that is passed along in the HTTP request

z Collection ...y ClientCertificate: to get the certification fields fromthe

request issued by Web browser; the fields that you can request are specified in the X.509 standard

y QueryString: to get text such as namey Form: to get data from an HTML formy Cookies: to get the value of application-defined cookiey ServerVariables: to get HTTP information such as the

server name

Response object

z It is used to send information to the user and supports only Cookies as a collection (to set cookie values); it also supports a number of properties and methods

z Properties currently supported ..y Buffer: set to buffer page output at the server. When this is

set to true, the server will not send a response until all of the server scripts on the current page have been processed or until the Flush or End method has been called

y ContentType: to set the type of content (ie: text/HTML)y Expires: sets the expiration based on minutesy Status: returns the status line (the first line of the

response)

Response object

z Methods supported ...y AddHeader: adds an HTML header with a specified

valuey AppendToLog: appends a string to the end of the Web

server log filey BinaryWrite: writes binary data (es: ExcelSheet)y Clear: clears any buffered HTML outputy End: stops processing of the scripty Flush: sends all of the information in the buffery Redirect: to redirect the user to a different URLy Write: to write into the HTML stream

Server object

z Property...y ScriptTimeout: which allows yuo to set the value for

when the script processing will time out

z Methods ...y CreateObject: to create an instance of a server

component (ie: ActiveX component)y HTMLEncode: to encode specified string in HTMLy MapPath: to map the current virtual path to a physical

directory structurey URLEncode: applies URL encoding to a specified string

Session object

z It is used to store information about the current user’s Web-server session

z variables exists as long as the user’s session is activez Properties ...

y SessionID: contains the identifier if the current sessiony TimeOut: specifying time-out value for the session

z Methods ...y Abandon: abandons the current Web-server session,

destroying any objects

Application object

z It can store information that persists for the intire lifetime (the whole time that the IIS server is running) of the application (a group of pages with a common root); es : a page counter

z object is shared by all users (difficult to thread)

Base Components

z ActiveX Data Object (ADO)y connectivity to any ODBC-compliant database or OLE dby core functions that all data sources implementy ease to use, high speed, low memory overhead, minimal disk space

requirements

z Content Linking componentz FileSystem Component

y access text file stored on the server

z Browser capability Componenty capability of requesting browser

z Advertisement Rotator Componentz Third-Party Opportunities

ActiveX Component Tech.

z Developed by Microsoft for 2 platform (Win, Mach)z It is the answer to Sun Microsystem’s Java

languagez Allows programmer to full access to the capabilities

of the computer on which the component is running

z Security ? → Code Signingy CS allows the developer of an ActiveX component to

attach a digital seal of approval to his component

VBScript

z Web centric dialect of MS popular Visual Basicz It ships with IE 3.0z It can reside on Web Pages and interacts with

HTML tagz Object oriented: VBScript Object Model

VBScript Object Model

WindowFrame

History Navigator Document Location Script

Object Link Form Anchor

Element

ActiveX controlActiveX component

Java Applet

Solid lines indicateone-to-one relationship;

Dashed lines indicate one-to-many relationship

Database Access

z Database Access component uses Active Data Objects (ADO) to provide easy access to information stored in a database

z Open Database Connectivity (ODBC) Standard

ADO

ASP files

WEBServer

ODBC Driver Manager(WinNT Control Panel)

VBS

Access db

SQL db

Win NT OS

Database Access

z Identify the DataBasez Create Component Instance (ADO)z Display the ResultSet (VBScript)

Identify the Database

z You must identify the database in the ODBC application in Control Panel (ODBC icon)

z Data sources for use with the Web server need to be of the System type

z Choose the Driver (Microsoft Access Driver)z Data Source Name used in ASP file

Identify the Database

z You need to create an instance of an object

z For the Database Access component, you also need to specify the ODBC data source by opening a connection to the database

z Use the Database Access component’s Executemethod to issue a SQL SELECT (SQLQuery) to the database and store the returned records in a result set (List)

Create Component Instance

Create Component Instance

<%Public OBJdbConnectionPublic ListDim SQLQuerySet OBJdbConnection =

Server.CreateObject("ADODB.Connection")OBJdbConnection.Open(”DatabaseName”)SQLQuery = "SELECT * FROM Table”Set List = OBJdbConnection.Execute(SQLQuery) %>

Display the Result Set

z Performing a loop through the rows of the result set (RSList)

z The returned data is displayed in HTML table rows in Db.asp

z VBScript Do...Loop statement

z Mix HTML tag with VBScript !!!!!

Display the Result Set

<TABLE><% Do While Not List.EOF %> <TR><TD BGCOLOR="f7efde" ALIGN=CENTER><FONT STYLE="ARIAL NARROW" SIZE=1><%= List(”Field1")%> </FONT></TD> <TD BGCOLOR="f7efde" ALIGN=CENTER> <FONT STYLE="ARIAL NARROW" SIZE=1><%= RSList(”Field2") & ", " %> <%= List(”Field3") %> </FONT></TD> </TR><% List.MoveNext Loop %>

Display the Result Set

Book.mdb

ODBC Driver Manager

asp file

<% Public OBJdbConnectionPublic ListDim SQLQuerySet OBJdbConnection = Server.CreateObject("ADODB.Connection") OBJdbConnection.Open("Bookdb") SQLQuery = "SELECT * FROM Table_Book" Set List = OBJdbConnection.Execute(SQLQuery) %><TABLE><TR><TH> Author</TH><TH>Title</TH><TH>Email Address</TH></TR><% Do While Not List.EOF %><TR><TD BGCOLOR="f7efde" ALIGN=CENTER><FONT STYLE="ARIAL NARROW" SIZE=1> <% = List("Author") %> </FONT></TD><TD BGCOLOR="f7efde" ALIGN=CENTER> <FONT STYLE="ARIAL NARROW"

SIZE=1> <% = List("Title") %> </FONT></TD><TD BGCOLOR="f7efde" ALIGN=CENTER><FONT STYLE="ARIAL NARROW"

SIZE=1> <a href=mailto:// <% = List("Email") %> >Mail to the Authors</a></FONT></TD></TR> <% List.MoveNext Loop %><% OBJdbConnection.Close Set List = Nothing Set OBJdbConnection = Nothing %>

Examples: ASP pages

ASP Technology

Example 1: Hello World

<HTML><BODY><% For i = 3 To 7 %> <FONT SIZE=<% = i %>> Hello World!<BR> <% Next %> </BODY> </HTML>

z Warning! This is an .asp file (not a .htm) and it is located in a site in which a IIS 3.0 Web Server runs

z .ASP file !

Example 2: Query Form

Example 2: Query Formz <HTML><HEAD><TITLE>Order</TITLE></HEAD><BODY>z <H2>Sample Order Form</H2><P>z Please provide the following information, then click

Submit:z <FORM METHOD="POST” ACTION="response.asp"><P>z First Name: <INPUT NAME="fname" SIZE="48"><P>z Last Name: <INPUT NAME="lname" SIZE="48"><P>z Title: <INPUT NAME="title" TYPE=RADIO VALUE="mr">z Mr.<INPUT NAME="title" TYPE=RADIO VALUE="ms">z Ms.<P><INPUT TYPE=SUBMIT><INPUT TYPE=RESET>z </FORM></BODY></HTML>

<HTML><HEAD><TITLE>RESPONSE TO FORM.HTML</TITLE></HEAD><BODY><% Title = Request.Form("title") LastName = Request.Form("lname")If Title = "mr" Then %> Mr. <%= LastName %> <% ElseIf Title = "ms" Then %> Ms. <%= LastName %> <% Else %><%= Request.Form("fname") & " " & LastName %><% End If %></BODY></HTML>

form.html

response.asp

Example 3: Hello World

<HTML><HEAD><TITLE> VBScript example </TITLE></HEAD><BODY><PRE><SCRIPT LANGUAGE = "VBSCRIPT">'Progressively larger messageFor I=3 to 6Document.write("<FONT FACE=Arial

SIZE = "&i&">")document.writeln("Hello World !!!")Next</SCRIPT></PRE></BODY></HTML>

z Client side VBScriptz .HTML file !

file.html

Example 4: Input control

Example 4: Input control

z <HTML><HEAD><TITLE>VBScript Example </TITLE>z <SCRIPT LANGUAGE = "VBSCRIPT">z Sub cmdSubmit_OnClickz Dim frmFormz Set frmForm = Document.NameOKz If frmForm.txtText1.Value ="" Thenz MsgBox "Type your name before you push SUBMIT."z Else z frmForm.Submitz End Ifz End Sub z </SCRIPT>z </HEAD><BODY><FORM NAME="NameOK">z Enter your name:z <INPUT NAME="txtText1" TYPE="TEXT" SIZE="25"><P>z <INPUT NAME="cmdSubmit" TYPE="BUTTON" VALUE="SUBMIT">z </FORM></BODY></HTML>

file.html

Example 5: Browser Type

<HTML><HEAD><TITLE>Browser Properties</TITLE></HEAD><BODY BGCOLOR=#FFFFFF><% Set bc = Server.CreateObject("MSWC.BrowserType") %><H3>The following is a list of properties of your browser:</H3><TABLE BORDER=1><TR><TD>Browser Type</TD> <TD><%= bc.Browser %></TD><TR><TD>What Version</TD> <TD><%= bc.Version %></TD><TR><TD>Major Version</TD> <TD><%= bc.Majorver %></TD><TR><TD>Minor Version</TD> <TD><%= bc.Minorver %></TD><TR><TD>Frames</TD> <TD><%= CStr(CBool(bc.Frames)) %></TD><TR><TD>Tables</TD> <TD><%= CStr(CBool(bc.Tables)) %></TD><TR><TD>Cookies</TD> <TD><%= CStr(CBool(bc.cookies)) %></TD><TR><TD>BackG Sound</TD><TD><%=CStr(CBool(bc.BackgroundSounds))%></TD><TR><TD>VBScript</TD> <TD><%= CStr(CBool(bc.VBScript)) %></TD><TR><TD>JavaScript</TD><TD><%= CStr(CBool(bc.Javascript)) %></TD></TABLE><BR><BR></BODY></HTML>

Example 5: Browser Type

Rest of the World

z Unix Flavour / Apache z Netscape Web Server (Unix, WinNT, Solaris)z Oracle Web Server

References

z www.microsoft.comy sitebuilder/archive/features/aspover.htm (by N.W. Cluts)

z MS Internet Information Server IIS 3.0 (White Paper)

z Tutorial about ASP files in the IIS 3.0 app.z Byte Magazine (March 1997):”A Visual Basic for Web ...”

by R. Dobsonz MS Active Server Page Tutorial (IIS 3.0)

top related