0% found this document useful (0 votes)
334 views52 pages

ASP (Active Server Page) : Morteza Sargolzaie Javan IT Scientific Society

This document discusses dynamic web pages created using Active Server Pages (ASP). It provides an overview of static versus dynamic web pages, server-side versus client-side processing, and different technologies for creating dynamic pages including ASP, PHP, and Java Server Pages. It also describes what an ASP file is, how ASP files interact with the server and browser, and how to install and run ASP on Microsoft's Internet Information Services web server.

Uploaded by

Ankit Nimavat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
334 views52 pages

ASP (Active Server Page) : Morteza Sargolzaie Javan IT Scientific Society

This document discusses dynamic web pages created using Active Server Pages (ASP). It provides an overview of static versus dynamic web pages, server-side versus client-side processing, and different technologies for creating dynamic pages including ASP, PHP, and Java Server Pages. It also describes what an ASP file is, how ASP files interact with the server and browser, and how to install and run ASP on Microsoft's Internet Information Services web server.

Uploaded by

Ankit Nimavat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 52

‫طراحي صفحات وب پويا‬

)‫(برنامه نويسي سمت سرور‬

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

IT Scientific Society - December 2006 2


Static Web Page Delivery
Web Server
1 3 Web server locates .htm file
Author writes
HTML
4 HTML stream returned to browser

2 5
Client requests page Browser processes
page

IT Scientific Society - December 2006 3


Client
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 4


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 6


Server-side Dynamic Page Delivery
Web Server
1 3 Web server locates instructions file

Author writes 4 Web server processes instructions to create HTML


instructions
5 HTML stream returned to browser

2 6
Client requests page Browser processes
page

IT Scientific Society - December 2006 7


Client
Client-side Web Page Delivery
Web Server
3 Web server locates instructions file
1
Author writes 4 HTML and script are returned to browser
instructions

5 Web browser processes script to


create HTML
2
Client requests page

6 Browser displays HTML

Client
IT Scientific Society - December 2006 8
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 9


?Server-side scripts or Client-side scripts
 Server-side  Client-side
 Processed by server  Processed by browser
 Does not rely on browser  Does not depend on web
support server requirements
 Provide browser with data  Does not need to interact
that does not reside on with server to create
client content
 Script code not visible in  processed by browser
page source  Script code is viewable in
 Can page source
 Manage sessions
(shopping baskets, etc.)
 Database processing

IT Scientific Society - December 2006 10


Server- and Client-side Scripting
Web Server
1 3 Web server locates page file

Author writes 4 Web server asks script engines to process scripts & generate HTML
page code
5 HTML stream passed back to server

6
Browser processes
2 client side scripts
Client requests page 7
Browser processes
HTML & displays
page
Client
IT Scientific Society - December 2006 11
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 12


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 13


?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 14


?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 15


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 16


Client/Server Interaction for ASP Files
Server

Server locates
Client requests Client
the ASP file on
the hard drive ASP File
and parses it,
removing all
ASP script and
replacing it with
HTML text Server returns HTML
text to client

IT Scientific Society - December 2006 17

Taken from Mitchell & Atkinson (2000)


Client/Server Interaction for ASP Files
<HTML>
<HEAD> <TITLE>Hello World</TITLE>
</HEAD><BODY>
<%
File On ' This will print to the browser the 
Server ' words Hello, ASP World.
response.write "Hello, ASP World!"
%>
</BODY></HTML>

<HTML>
<HEAD> <TITLE>Hello World</TITLE>
Result on </HEAD><BODY>
Client Hello, ASP World!
</BODY></HTML>

IT Scientific Society - December 2006 18


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 19


Installing IIS

IT Scientific Society - December 2006 20


Running IIS

IT Scientific Society - December 2006 21


IIS Environment

IT Scientific Society - December 2006 22


IIS Default Folder

IT Scientific Society - December 2006 23


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 24


?What Does ASP Look Like in Action

IT Scientific Society - December 2006 25


What Does ASP Look Like in Action?
 What HTML “looks like”
<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>

IT Scientific Society - December 2006 26


?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 27


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 28


ASP Objects
 Request
 Response
 Server
 Application
 Session

IT Scientific Society - December 2006 29


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

IT Scientific Society - December 2006 30


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 31


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 32


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 33


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

IT Scientific Society - December 2006 34


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 35


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 36


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 37


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 38


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 39


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 40


Variables
 <html>
<body>

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

</body>
</html>

IT Scientific Society - December 2006 41


Arrays
 <html>
<body>

<%
Dim famname(6),i
famname(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 42
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 43


Example (VB)
 <html>
<body>
<%
dim h
h=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 44


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 45


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 46
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 47
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 48


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

IT Scientific Society - December 2006 49


Process Information
<body> Welcome
<%
response.write(request.querystring("fname"))
response.write(" " & request.querystring("lname"))
%>
</body>

IT Scientific Society - December 2006 50


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 51


Example of Cookies
<html>
<body>
<%
dim numvisits
response.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 if
end if
%>
</body>
</html>

IT Scientific Society - December 2006 52


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

IT Scientific Society - December 2006 53

You might also like