asp ppt

52
ASP (Active Server Page) Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society ا وي پ وب حاب ف ص ي ح را ط)ور ر س ت م س ي س ي و پ ه م ا ري ب(

Upload: ankit-nimavat

Post on 23-Nov-2014

113 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: asp ppt

ASP (Active Server Page)

Morteza Sargolzaie Javanhttp://www.msjavan.tkIT Scientific Society

پويا وب صفحات طراحي) سرور) سمت نويسي برنامه

Page 2: asp ppt

IT Scientific Society - December 2006 2

Static Web Pages Page content doesn’t change.

Same every time it is delivered by the web server

Pages we have created so far

Page 3: asp ppt

IT Scientific Society - December 2006 3

Static Web Page Delivery

Web Server

Client

1Author writesHTML

2Client requests page

3 Web server locates .htm file

HTML stream returned to browser4

5Browser processespage

Page 4: asp ppt

IT Scientific Society - December 2006 4

Dynamic Web Pages Created on the fly based on user actions

or current conditions. Allows the page to be customized to the

user and the situation.

Page 5: asp ppt

IT Scientific Society - December 2006 6

Server-side vs. Client-side Processing

Computer processing can happen in two locations Server:

Accepts request, finds page, sends it Client:

Gets HTML (or more?) from net, processes it, displays it

Advanced things can happen on one or both sides

Page 6: asp ppt

IT Scientific Society - December 2006 7

Server-side Dynamic Page Delivery

Web Server

Client

1Author writesinstructions

2Client requests page

3 Web server locates instructions file

HTML stream returned to browser5

6Browser processespage

4 Web server processes instructions to create HTML

Page 7: asp ppt

IT Scientific Society - December 2006 8

Client-side Web Page DeliveryWeb Server

Client

1Author writesinstructions

2Client requests page

3 Web server locates instructions file

HTML and script are returned to browser

5

6 Browser displays HTML

4

Web browser processes script to create HTML

Page 8: asp ppt

IT Scientific Society - December 2006 9

Many Technology Choices Client-Side Technologies:

Scripting languages: JavaScript, VBScript Java applets XML

Server-Side Alternatives: CGI Active Server Pages (ASP) PHP Java Server Pages (JSP) ColdFusion

Page 9: asp ppt

IT Scientific Society - December 2006 10

Server-side scripts or Client-side scripts?

Server-side Processed by server Does not rely on browser

support Provide browser with data

that does not reside on client

Script code not visible in page source

Can Manage sessions

(shopping baskets, etc.) Database processing

Client-side Processed by browser Does not depend on web

server requirements Does not need to interact

with server to create content

processed by browser Script code is viewable in

page source

Page 10: asp ppt

IT Scientific Society - December 2006 11

Server- and Client-side Scripting

Web Server

Client

1Author writespage code

2Client requests page

3 Web server locates page file

HTML stream passed back to server5

6Browser processesclient side scripts

4 Web server asks script engines to process scripts & generate HTML

7Browser processesHTML & displayspage

Page 11: asp ppt

IT Scientific Society - December 2006 12

ASP – Middleware for Windows platform

ASP stands for Active Server Pages

VBScript is the default scripting language for ASP

If you are looking for some special software to write an ASP page, Microsoft Visual InterDev is the best tool for you.

Page 12: asp ppt

IT Scientific Society - December 2006 13

ASP – Middleware for Windows platform Active Server Page can include both client side

and server side scripts.

In an ASP page VBScript is usually used as the server side and Java Script as the client side scripting language

Page 13: asp ppt

IT Scientific Society - December 2006 14

What is an ASP file?

An ASP file is just the same as an HTML file An ASP file can contain text, HTML, XML, and

scripts Scripts in an ASP file are executed on the server An ASP file has the file extension *.asp

Page 14: asp ppt

IT Scientific Society - December 2006 15

What is an ASP file?

<HTML><HEAD> <TITLE>Hello World</TITLE></HEAD><BODY><%

' This will print to the browser the ' words Hello, ASP World.

response.write "Hello, ASP World!"%></BODY></HTML>

Page 15: asp ppt

IT Scientific Society - December 2006 16

What can be done with ASP

Dynamically edit, change or add any content of a Web page

Respond to user queries or data submitted from HTML forms

Access any data or databases and return the results to a browser

Page 16: asp ppt

IT Scientific Society - December 2006 17

Client requests ASP File

Client

Server

Server returns HTML text to client

Server locates the ASP file on the hard drive and parses it, removing all ASP script and replacing it with HTML text

Client/Server Interaction for ASP Files

Taken from Mitchell & Atkinson (2000)

Page 17: asp ppt

IT Scientific Society - December 2006 18

Client/Server Interaction for ASP Files

<HTML><HEAD> <TITLE>Hello World</TITLE></HEAD><BODY><%

' This will print to the browser the ' words Hello, ASP World.

response.write "Hello, ASP World!"%></BODY></HTML>

<HTML><HEAD> <TITLE>Hello World</TITLE></HEAD><BODY>

Hello, ASP World!</BODY></HTML>

Result onClient

File OnServer

Page 18: asp ppt

IT Scientific Society - December 2006 19

ASP compatibility ASP is an engine/program built into Internet Information

Server (IIS) / Personal Web Server (PWS)

PWS is a smaller - but fully functional - version of IIS

To run IIS you must have Windows NT 4.0 or later

To run PWS you must have Windows 95 or later

Page 19: asp ppt

IT Scientific Society - December 2006 20

Installing IIS

Page 20: asp ppt

IT Scientific Society - December 2006 21

Running IIS

Page 21: asp ppt

IT Scientific Society - December 2006 22

IIS Environment

Page 22: asp ppt

IT Scientific Society - December 2006 23

IIS Default Folder

Page 23: asp ppt

IT Scientific Society - December 2006 24

Opening an ASP File

http://localhost/page.asp

http://127.0.0.1/page.asp

http://[Computer-name]/page.asp

Page 24: asp ppt

IT Scientific Society - December 2006 25

What Does ASP Look Like in Action?

Page 25: asp ppt

IT Scientific Society - December 2006 26

What Does ASP Look Like in Action?

<p>Analytical Ultracentrifugation Workshop (May 21-23, 2001) and Symposium (May 24, 2001) at the National Analytical Ultracentrifugation Facility, Storrs, Conn. For additional information</p> <ul> <li><a href="http://www.ucc.uconn.edu/~wwwbiotc/99wkshp.html" target="_blank"> National Analytical Ultracentrifugation Facility</a></li> <li><a href="naufworkshop.asp">Analytical Ultracentrifugation Workshop and Symposium Description and Registration (PDF Format)</a></li> </ul>

What HTML “looks like”

Page 26: asp ppt

IT Scientific Society - December 2006 27

What Does ASP Look Like in Action?

What the “real code” looks like*

<% If Today < CDate("5/25/01") Then %> <p>Analytical Ultracentrifugation Workshop (May 21-23, 2001) and Symposium (May 24, 2001) at the National Analytical Ultracentrifugation Facility, Storrs, Conn. For additional information</p> <ul><li><a href="http://www.ucc.uconn.edu/~wwwbiotc/99wkshp.html" target="_blank">National Analytical Ultracentrifugation Facility</a></li> <li><a href="naufworkshop.asp">Analytical Ultracentrifugation Workshop and Symposium Description and Registration (PDF Format)</a></li> </ul><% End If %>

Page 27: asp ppt

IT Scientific Society - December 2006 28

ASP Object Model ASP itself is not Object-Oriented. ASP can

use objects but cannot define new objects Composed of

5 objects 5 components

Page 28: asp ppt

IT Scientific Society - December 2006 29

ASP Objects Request Response Server Application Session

Page 29: asp ppt

IT Scientific Society - December 2006 30

ASP Components Scripting Objects Component ADO (ActiveX Data Objects) Component Ad Rotator Component Browser Capabilities Component Content Linking Component

Page 30: asp ppt

IT Scientific Society - December 2006 31

Request Can get input from query string or form Can get cookie information Can also get total bytes, certificate, server variables Example <% Request.QueryString

(“fname”) %>

Page 31: asp ppt

IT Scientific Society - December 2006 32

Response Can send output to user through web

page Can set cookie values Can set character set, expiration Can clear, write, flush output Can redirect Example <% Response.Write “message”

%>

Page 32: asp ppt

IT Scientific Society - December 2006 33

Session Store user information during request and

response and request and response…. Want to identify, maintain user

information or state in stateless HTTP protocol

Client has an id number and expiration time from last request or expires

Client can terminate or abandon causing Session object to be destroyed as well

Page 33: asp ppt

IT Scientific Society - December 2006 34

Application Information about entire website Global variables Example is a counter Lock and UnLock to access to update

Page 34: asp ppt

IT Scientific Society - December 2006 35

Server Server related utility functions Script time out for running say a DB query Create an object like DB object Can enable URL encoding Example:

Request.ServerVariable(REMOTE_ADDR)

Page 35: asp ppt

IT Scientific Society - December 2006 36

VBscript <% … %> open and close script area <% Response.Write (“message”) %> <% = “message” %> <% = sStr1 %> & is concatenate operator <% Request.QueryString(“fname”) %> <% Request (fname) %> Server.CreateObject(“ADODB.connection”) Include statement for reuse of say login,

password

Page 36: asp ppt

IT Scientific Society - December 2006 37

Logic If … then …. Else … end if Not case sensitive For statement

For I = 1 to 8 statements Next While statement Wend Case statement

Page 37: asp ppt

IT Scientific Society - December 2006 38

Functions Type casting like CStr(expression) Checking type, Date, Searching (strings) Math abs(number) Also, user defined function and subroutines. Function can return a value, subroutines cannot,

and example: Function add(a,b) add=a+b End Function

Page 38: asp ppt

IT Scientific Society - December 2006 39

Operators Concatenation operator is & (watch use of ‘ and “ to build string with

variables) + - * < > or and mod etc. = also = to print out

Page 39: asp ppt

IT Scientific Society - December 2006 40

ASP Syntax VBScript:<html> <body> <% response.write("Hello World!") %> </body>

</html>

JavaScript<%@ language="javascript" %><html> <body> <% Response.Write("Hello World!") %> </body> </html>

Page 40: asp ppt

IT Scientific Society - December 2006 41

Variables <html>

<body>

<%dim namename=“Javan"response.write("My name is: " & name)%>

</body></html>

Page 41: asp ppt

IT Scientific Society - December 2006 42

Arrays <html>

<body>

<%Dim famname(6),ifamname(1) = "Jan Egil"famname(2) = "Tove"famname(3) = "Hege"famname(4) = "Stale"famname(5) = "Kai Jim"famname(6) = "Borge"

For i = 1 to 6      response.write(famname(i) & "<br />")Next%>

</body></html>

Page 42: asp ppt

IT Scientific Society - December 2006 43

Loops <html>

<body>

<%dim i for i=1 to 6   response.write("<h" & i & "> Header " & i & "</h" & i & ">")next%>

</body></html>

Page 43: asp ppt

IT Scientific Society - December 2006 44

Example (VB) <html>

<body><%dim hh=hour(now())

response.write("<p>" & now() &”</p>”)

If h<12 then   response.write("Good Morning!")else   response.write("Good day!")end if%></body></html>

Page 44: asp ppt

IT Scientific Society - December 2006 45

Example (JavaScipt) <%@ language="javascript" %>

<html><body><%var d=new Date()var h=d.getHours()

Response.Write("<p>“ + d + “</p>”)if (h<12)   {   Response.Write("Good Morning!")   }else   {   Response.Write("Good day!")   }%></body></html>

Page 45: asp ppt

IT Scientific Society - December 2006 46

Procedures (VB)<html><head> <%

sub vbproc(num1,num2) response.write(num1*num2)

end sub %></head><body> <p>Result: <%call vbproc(3,4)%></p> </body></html>

Page 46: asp ppt

IT Scientific Society - December 2006 47

Procedures (JavaScript)<%@ language="javascript" %><html><head><% function jsproc(num1,num2){

Response.Write(num1*num2)}%></head><body> <p>Result: <%jsproc(3,4)%></p></body></html>

Page 47: asp ppt

IT Scientific Society - December 2006 48

Forms<form method="get" action="simpleform.asp"> First Name: <input type="text" name="fname"> <br /> Last Name: <input type="text" name="lname"> <br /><br /> <input type="submit" value="Submit"></form>

Page 48: asp ppt

IT Scientific Society - December 2006 49

Sending Information over get method/simpleform.asp?fname=Morteza&lname=Javan

Page 49: asp ppt

IT Scientific Society - December 2006 50

Process Information<body> Welcome <%

response.write(request.querystring("fname")) response.write(" " & request.querystring("lname"))

%></body>

Page 50: asp ppt

IT Scientific Society - December 2006 51

Cookies Create a Cookie:<%

Response.Cookies("firstname")="Alex" %> Retrieve a Cookie value:<%

fname=Request.Cookies("firstname") response.write("Firstname=" & fname)

%>

Page 51: asp ppt

IT Scientific Society - December 2006 52

Example of Cookies<html><body><%dim numvisitsresponse.cookies("NumVisits").Expires=date+365 numvisits=request.cookies("NumVisits")

if numvisits="" then   response.cookies("NumVisits")=1   response.write("Welcome! This is the first time you are visiting this Web page.")else   response.cookies("NumVisits")=numvisits+1   response.write("You have visited this Web page " & numvisits)   if numvisits=1 then     response.write " time before!"   else     response.write " times before!"   end ifend if%></body></html>

Page 52: asp ppt

IT Scientific Society - December 2006 53

Online ASP Tutorials

http://www.vallin.com/pub/1/asp1.asp http://www.4guysfromrolla.com/ http://www.15seconds.com/ http://www.learnasp.com/ http://www.w3schools.com http://msdn.microsoft.com/library/default.asp?

URL=/library/en-us/dnasp/html/asptutorial.asp