Active Server Pages
Active Server Pages
What Is ASP
• <html><body>
<%
response.write("My first ASP script!")
%>
</body></html>
• <html><body>
<%="Hello World!"%>
</body></html>
Using VBScript in ASP
• <html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
Using JavaScript in ASP
• <%@ language="javascript"%>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>
Lifetime of Variables
• To declare variables accessible to more than
one ASP file, declare them as session variables
or application variables.
• Session Variables
• Session variables are used to store information
about ONE single user, and are available to all
pages in one application. Typically information
stored in session variables are name, id, and
preferences.
Lifetime of Variables
• Application Variables
• Application variables are also available to
all pages in one application. Application
variables are used to store information
about ALL users in one specific application
Procedures in VBScript
• <html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
</body>
</html>
Procedure in javascript
• <%@ language="javascript" %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
<p>Result: <%jsproc(3,4)%></p>
</body>
</html>
Response Object
• <%
response.Clear
%>
• <%
Response.Redirect "http://www.w3schools.com"
%>
ASP Request Object
• The Request object is used to get
information from a visitor.
Collections
Collection Description
ClientCertific Contains all the field values stored in
ate the client certificate
Cookies Contains all the cookie values sent in a
HTTP request
Form Contains all the form (input) values from
a form that uses the post method
QueryString Contains all the variable values in a
HTTP query string
ServerVariable Contains all the server variable values
s
Request.QueryString
• <body>
Welcome
<%
response.write(request.querystring("fnam
e"))
response.write(" " &
request.querystring("lname"))
%>
</body>
Request.Form
• <body>
Welcome
<%
response.write(request.form("fname"))
response.write(" " &
request.form("lname"))
%>
</body>
What is a Cookie?
• Collections
Collection Description
Contents Contains all the items
appended to the session
through a script command
StaticObjects Contains all the objects
appended to the session
with the HTML <object> tag
Session object methods
• <%
Session("name")="Hege"
Session.Abandon
Response.Write(Session("name"))
%>
• <%
Session.Contents.RemoveAll()
%>
When does a Session Start?
• <%
Session("username")="Donald Duck"
Session("age")=50
%>
• Welcome <
%Response.Write(Session("username"))
%>
ASP Application Object
• Collections
Collection Description
Contents Contains all the items
appended to the application
through a script command
StaticObjects Contains all the objects
appended to the application
with the HTML <object> tag
Application object methods
• <%
Application("test1")=("First test")
Application("test2")=("Second test")
Application("test3")=("Third test")
Application.Contents.Remove("test2")
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br />")
next
%>
Output:
test1=First test
test3=Third test
Example
• <%
Application.Lock
Application("visits")=Application("visits")+1
Application.Unlock
%>
• Methods:
Method Description
Contents.Remove Deletes an item from the Contents collection
• <html>
<head>
</head>
<body>
<p>There are <
%response.write(Application("visitors"))
%> online now!</p>
</body>
</html>
What is ASP?
VBScript ASP
• Request
• Response
• Server
• Application
• Session
ASP Components
Response
Application
Session
What Does ASP Look Like
in Action?
What Does ASP Look Like
in Action?
• Personal Preferences
Microsoft FrontPage
Allaire HomeSite
• Other Tools
Microsoft Access
Visual Basic
Microsoft Visual InterDev
Visual Studio .NET
Other Non-Microsoft Tools (never used them)
ASP Reference Tools
• An ASP page
Needs the .ASP file extension to indicate to
the server that there is code the server must
interpret
A series of commands on one page
• An ASP application is a series of pages
that are linked together through code and
the content linking component to function
as a logical unit
“ASP Page” vs.
“ASP Application”
• ObjectWatch Newsletter
J2EE versus .NET--The Latest Benchmark
http://www.objectwatch.com/issue_42.htm
• Conclusion: ASP/.NET technology
Hardware/Software infrastructure is LESS
Development time is SHORTER
Development cost is LESS
Administrative cost is LESS
Application performance is FASTER and can
absorb HIGHER TRAFFIC
ASP Doesn’t Work with
Client-Side Scripting
• ASP Pages
Chapter Contacts
OCSTC Home Page
• ASP Applications
Chapter Meetings
Job Information
• ASP and XML
XML assignment
Conclusion: ASP and the
Technical Communicator
• Presentation Link
http://www.ocstc.org/meeting_archive.asp
• Sample XML/ASP application
ASP Position Paper
http://www.ocstc.org/Jeff_XMLWork/XMLandASP.pdf
Output Page
http://www.ocstc.org/Jeff_XMLWork/default.asp
XML Data Page
http://www.ocstc.org/Jeff_XMLWork/products.asp
A Final Thought—1...
• Consider this
Private Sub Madness ()
Call Method
End Sub
• Translation?
“There’s a Method in the Madness”
A Final Thought—2...