asp (active server page)
DESCRIPTION
ASP (Active Server Page). طراحي صفحات وب پويا (برنامه نويسي سمت سرور). Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society. Static Web Pages. Page content doesn ’ t change. Same every time it is delivered by the web server Pages we have created so far. - PowerPoint PPT PresentationTRANSCRIPT
ASP (Active Server Page)
Morteza Sargolzaie Javanhttp://www.msjavan.tkIT Scientific Society
پويا وب صفحات طراحي) سرور) سمت نويسي برنامه
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
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
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.
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
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
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
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
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
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
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.
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
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
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>
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
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)
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
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
IT Scientific Society - December 2006 20
Installing IIS
IT Scientific Society - December 2006 21
Running IIS
IT Scientific Society - December 2006 22
IIS Environment
IT Scientific Society - December 2006 23
IIS Default Folder
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
IT Scientific Society - December 2006 25
What Does ASP Look Like in Action?
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”
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 %>
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
IT Scientific Society - December 2006 29
ASP Objects Request Response Server Application Session
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
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”) %>
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”
%>
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
IT Scientific Society - December 2006 34
Application Information about entire website Global variables Example is a counter Lock and UnLock to access to update
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)
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
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
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
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
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>
IT Scientific Society - December 2006 41
Variables <html>
<body>
<%dim namename=“Javan"response.write("My name is: " & name)%>
</body></html>
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>
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>
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>
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>
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>
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>
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>
IT Scientific Society - December 2006 49
Sending Information over get method/simpleform.asp?fname=Morteza&lname=Javan
IT Scientific Society - December 2006 50
Process Information<body> Welcome <%
response.write(request.querystring("fname")) response.write(" " & request.querystring("lname"))
%></body>
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)
%>
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>
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