+ All Categories
Home > Documents > 1 ASP History/Components Active Server History: Introduced July 1996 Bundled with Internet...

1 ASP History/Components Active Server History: Introduced July 1996 Bundled with Internet...

Date post: 21-Dec-2015
Category:
View: 217 times
Download: 4 times
Share this document with a friend
Popular Tags:
34
1 ASP History/Components Active Server History: Introduced July 1996 Bundled with Internet Information Server (IIS) 3,0 March of 1997 ASP 2.0 introduced in 1998 Shipped with IIS 4.0 AS 3.0 shipped as part of Windows 2000 IIS 5.0 IS considered to be more of a Technology than a language It's syntax is comprised of a ASP, HTML tags and pure text.
Transcript

1

ASP History/Components Active Server History:

Introduced July 1996 Bundled with Internet Information Server (IIS) 3,0

March of 1997 ASP 2.0 introduced in 1998 Shipped with IIS 4.0 AS 3.0 shipped as part of Windows 2000 IIS 5.0 IS considered to be more of a Technology than a

language It's syntax is comprised of a ASP, HTML tags and

pure text.

2

ASP Capabilities ASP can

Generates dynamic web pages Processes the contents of HTML forms Creates database driven web pages Tracks user sessions: can store information about

users from the moment they arrived at web site tell the moment they leave.

Create searchable web pages Detect capability different browsers Send e-mail Integrate custom components of your Web site

including server side components created with Visual Basic ,C++ or Java.

3

ASP Flexibility

Static VS

DynamicWebsites

4

Simple Page<HTML>

<HEAD> <TITLE> Hungry ASP Example </TITLE> </Head>

<BODY>

<%

For i = 1 to 10

var=var&"very,"

Response.Write(i&":"&var&"<BR>")

NEXT

%>

<HR>

I am <%=var%> Hungry!!

</BODY>

</HTML>

5

Object Overview

Objects Contain:Methods

Determine the things

PropertiesCan be used to set the state of and object

Collections Constitutes a set of Keys and Value pairs related to

the object.

6

Object Example

A Dictionary :Methods

Look things up, used as a door stop.

PropertiesHas a certain number of pages, and a particular

author.

Collections Each section corresponds to the text it contains.

7

ASP ComponentsAd rotator component - used to display banner advertisements

on pages a WebSite.

Web browsers capabilities component - to be used to display different HTML content according to the capabilities of different browsers. For example you can use is component to display Web pages with frames only to frames compliant browsers.

Content linking component- is used to live together several HTML pages so they can be navigating easily. for example you can use this component display the pages that online book;

Counters component -the counters component and keep track of the number of visitors to your WebSite. You can use the counters component add a hit counter to a Web page.

8

ASP Components (cont)Content rotator component - can be used to rotate through HTML

content I page. For example you can use the component to randomly display different announcements on the home page of your WebSite.

Page counter - is exactly like counter component into the used to track visitors into a hit counter to a particular Web page.

Permissions checker component- can be used to display links to Web pages only to those users to their permission to see them.

Collaboration data objects the collaboration data objects enables sending and retrieving of information from within your active server pages. For example you can send an email after a new user registers at your WebSite

ActiveX data objects enabling you to retrieve information stored in a databases.

9

Page Scope Page scope- is created on a single

page and dies when the processing of the page ends

Can be created with server.Createobject() or the HTML <object> tag.

10

Page Scope Example

<HTML><HEAD><TITLE> Objectst - ASP Example</TITLE></HEAD><BODY><%set Mydict=Server.CreateObject("Scripting.Dictionary")MyDict.Add "CA", "California"MYDict.Add "OH", "OHIO"MyDict.Add "FL", "Florida" %>My dictionary has <%=Mydict.count%> entries.<BR>The first entry is <%=Mydict.Item("CA")%><BR></BODY></HTML>

11

Session Scope

Components are created for each visitor to your web site

Components do not leave memory until the visitor leaves your website

12

Buffering

Can be set as a default for the website IIS – “Enable Buffering”

Will not send page until the script completely processes

Response.Buffer=True must appear before any HTML or Script output otherwise an error will be issued.

13

Caching Browsers will sometimes present a page from “Cache”

instead of retrieving it from the website. The browser can be set to always go to the website for

pages ASP provides Expires, ExpiresAbsolute for websites and

CacheControl (for proxy servers) Response.Expires = 0 sets the page life to 0 minutes and

will always request fresh pages Response.ExpiresAbsolute = “#Jan 1, 2010 00:00:00#

set the page to expire on midnight of 12/31/2009 Response.CacheControl = “Public” means anyone can

use the page, “Private” does not cache the pages

14

ASP Status Codes 1xx - Informational - Expermental 2xx - Success 3xx - Redirection 4xx - Client Error 5xx - Server Error

15

Navigating your User On occasion, you will need to redirect your user to another

page. (Access rights, Registration, Form completion etc) Response.Redirect “path/page.asp” Must be used before any text is outputted to the browser “Buffering” may need to be utilized.

16

Request Object Contains all of the information about the HTTP request

performed to retrieve an Active Server Page The request object contains three collections:

Querystring – used to pass information form the browser to the server. It appears after the ?

FormCollection - similar to the query string used to store variables posted within a HTML form

Server Variables – when a browser requesta a web page from a server, the request contains several headers

17

Request Object – Query StringAre typically not entered directly into the address bar of a browser .Firstpage.ASP

<html>

<head><title>Color Choice</title></head>

What is your favorite color?

<P>

<a href="nextpage.asp?favcolor=blue">blue</a>

<p>

<a href="nextpage.asp?favcolor=red">red</a>

</body>

</html>

18

Query String – ExampleNextPage.ASP

<html>

<head><title>Your Favorite Color</title></head>

<body>

<%

favColor = Request.QueryString( "favColor" )

%>

Your favorite color is <%=favColor%>!

</body>

</html>

19

URL Encoded Query StringUsed when the value of a query string contains a non alphanumeric character such as a space, quotation mark, comma period, etc .

<a href=”menupage.asp?favfood=chocolate cake">Chocolate Cake</a>

Would need to be implemented as follows<%

favfood = Server.URLEncode (“Chocolate Cake”)

%>

<a href=”menupage.asp?favfood=<%favfood%> ">Chocolate Cake</a>

20

Multiple Query String VariablesYou can pass multiple variables in the query string by utilizing the &...

<a href=”order.asp?entrée =steak&drink=pepsi">Steak and Pepsi</a>

...

order.asp<%

Response.Write Request.QueryString(“entrée”)

Response.Write Request.QueryString(“drink”)%>

You can pass multiple values to a variables in the query string by utilizing the & ...

<a href=”Flag.asp?fcolor=red&white&blue">USA</a>

<%

Response.Write Request.QueryString(“fcolor”) %>

Would produce: red, white, blue

21

Dumping QueryString Collection Mostly used in debugging an Active Server Page.

You can use a for.. next loop <%

for i = 1 to Request.QueryString.Count

Response.Write Request.QueryString(i) & “<br>”)next%>

You can also use a for.. each loop <%

for each thing in Request.QueryString

Response.Write thing & “ = “ & Request.QueryString(thing) & “<br>”)next %>

22

Query Strings Pros/Cons

Can be useful for passing small bits of information.

Always displayed in clear text; do not use for passing hidden data or large chunks of data.

Different browsers handle a different maximum limits of query string lengths

23

Request Object Contains all of the information about the HTTP request

performed to retrieve an Active Server Page The request object contains three collections:

Querystring – used to pass information form the browser to the server. It appears after the ?

FormCollection - similar to the query string used to store variables posted within a HTML form

Server Variables – When a browser requests a web page from a server it includes several headers which can be queried using this collection.

24

Forms Collection The forms collection is very similar to the

querystring collection.FormCollection - similar to the query string used to

store variables posted within a HTML form

25

Form ExampleColor.ASP<%

Dim color, state

color = "Blue"

state = "Ohio"

Function checked(firstVal, secondVal)

If firstVal = secondVal then

checked = " CHECKED"

End if

End Function

Function selected(firstVal, secondVal)

If firstVal = secondVal then

checked = " SELECTED"

End if

End Function

%>

<html>

<head><title>Color Choice using Buttons</title></head>

</body>

<form method="post" action="colorp.asp">

<B> ENTER YOUR FAVORITE COLOR

<BR> <input name="color" type="radio" value="Red" <%=checked(color, "red")%>> Red

<BR> <input name="color" type="radio" value="Blue" <%=checked(color, "blue")%>> Blue

<BR> <input name="color" type="radio" value="Green" <%=checked(color, "green")%>> Green

<BR> <input name="color" type="radio" value="Black" <%=checked(color, "black")%>> Black

<br>select your state

<select name="state"

<option Value="New York" <%=selected(state, "New York")%>>New York

<option Value="OHIO" <%=selected(state, "OHIO")%>>OHIO

<option Value="Florida" <%=selected(state, "Florida")%>>Florida

</Select>

<p>

<input type="submit" Value="save"

</form>

</body>

</html>

26

Form ExampleColorp.ASP

<%

for each thing in request.form

Response.Write thing & " "&Request.form(thing) &"<br>"

next

DIM state,color

state=Request.Form("state")

color=Request.Form("color")

%>

<html>

<head><title>Colors ..</title></head>

<body>

Do all of the people who live in <%=state%> have <%=color%> as their favorite color??

</body>

</html>

27

Form ExampleComment.ASP

<html>

<head><title>Your Comments Matter</title></head>

<body>

<form method="post" action="confirm.asp">

<p>Please enter your name: (L,F ) </b>

<input name="username" type="text" size=30>

<p> Please enter your comments:

<br> <textarea name="comments" cols=40 rows=5> </textarea>

<input type="submit" value="Send comments">

</form>

</body>

</ht

28

Form ExampleConfirm.asp

<%

DIM username,comments

username=Request.Form(“username”)

comments=Request.Form(“comments”)

%>

<html>

<head><title>Thanks ..</title></head>

<body>

Your name is : <%username%>

Your comments are: <%comments%>

</body>

</html>

29

Form ExampleConfirm.asp

<%

DIM username,comments

username=Request.Form(“username”)

comments=Request.Form(“comments”)

%>

<html>

<head><title>Thanks ..</title></head>

<body>

Your name is : <%username%>

Your comments are: <%comments%>

</body>

</html>

30

Form ExampleConfirm.asp

<%

DIM username,comments

username=Request.Form(“username”)

comments=Request.Form(“comments”)

%>

<html>

<head><title>Thanks ..</title></head>

<body>

Your name is : <%username%>

Your comments are: <%comments%>

</body>

</html>

31

ODBCOpen Database Connectivity (ODBC) is a standard or open application programming interface (application program interface) for accessing a database. By using ODBC statements in a program, you can access files in a number of different databases, including Access, Oracle, Sybase SQL Server, DB2. ODBC allows programs to use SQL requests that will access databases without having to know the proprietary interfaces to the databases. ODBC handles the SQL request and converts it into a request the individual database system understands.

32

Making An Oracle ConnectionDBinq.asp

<%

set conn = server.createobject("ADODB.Connection")

conn.open "Oracleadd","system","manager"

set rs = server.createobject("ADODB.Recordset")

SQLSTR = "SELECT * from system.address order by lastname"

rs.open SQLSTR, conn, 3, 3

while not rs.eof

ln = rs.fields("lastname")

response.write ln & "<br> "

rs.movenext

wend

conn.close

set rs = nothing

set conn = nothing

%>

</body>

</html>

33

Making An Oracle ConnectionFor a Connection object:

connection.Open ConnectionString, UserID, Password

For a Recordset object:

recordset.Open Source, ActiveConnection, CursorType, LockType

The Open method syntax has these parts.

Part Description

Connection An object variable representing an existing Connection object.

recordset An object variable representing an existing Recordset object.

ConnectionString Optional. A String containing connection information. See the ConnectionString property for details on valid settings.

UserID Optional. A String containing a user name to use when establishing the connection.

Password Optional. A String containing a password to use when establishing the connection.

Source Optional. A Variant that evaluates to a valid Command object variable name, an SQL statement, a table name, or a stored procedure call.

ActiveConnection Optional. A Variant that evaluates to a valid Connection object variable name or a String containing a definition for a connection.

34

Making An Oracle ConnectionCursorType Optional. A CursorTypeEnum value that determines the type of cursor that the provider should use when opening the Recordset. Can be one of the following constants:

adOpenForwardOnly, 0 (Default)

adOpenKeyset, 1

adOpenDynamic, 2

adOpenStatic, 3

LockType Optional. A LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the Recordset. Can be one of the following constants:

adLockReadOnly, 1

adLockPessimistic, 2

adLockOptimistic, 3

adLockBatchOptimistic, 4

See the LockType property for definitions of these settings.


Recommended