Title: Intro to ASP with VBScript
1Intro to ASP with VBScript
- Tom Whaley
- Department of Computer Science
- Washington and Lee University
- Part 3
- Introduction to ASP scripting with
- VBScript
2Active Server Pages
3ASP Basics
- ASP files use .asp extension instead of .html or
.htm - ASP files are HTML files with scripting embedded
- Server passes file to ASP processor
- After processing, scripting is removed before
sending to browser - ASP code is placed inside tags lt and gt
4The ASP Object Model
Server
Client
ServerObject
Request Object
Response Object
ApplicationObject
ObjectContext Object
SessionObject
5ASP Objects - Server Object
- Object for managing the web server. Our main use
will be to create objects on the server using the
CreateObject method. Set objRec
Server.CreateObject ("ADODB.Recordset")
6ASP Objects - Request Object
- Responsible for information sent from client to
ASP application. This corresponds closely to the
HTTP request both header and body. - Our main use will be to retrieve data sent via a
FORM using METHODPOST. Here the Request Object
has a Form collection for data sent. - strCriticName Request.Form("CriticName")This
takes the value that was entered in the
CriticName field of the form and stores it in the
variable strCriticName.
7ASP Objects - Response Object
- Responsible for information sent from application
to client. Corresponds to the HTTP response. - Our main use will be with the Write method to
display information on response page. - Response.Write ltH2gt John Wayne ltBRgt"This
would place this text in the response page we are
sending back to the client.
8ASP Built-in Objects - Not for us
- Application Object Object for managing the
application - virtual directory of pages. Used to
share global information among clients. - Session Object Each client accessing the
application gets a Session object. Helps keep
track of user-specific information during
session. - ObjectContext Object Has to do with transaction
scripts (all or nothing). Beyond the scope
9VBScript Assignment Statement
- Syntax ltvariablegt ltexpressiongt
- Semantics
- Compute value of expression
- Store this as new value of the variable
- Example Pay PayRate Hours
10VBScript If Statement
- Syntax If ltconditiongt Then ltlist of
statementsgt End If - ExampleIf Age gt 65 Then Price .85
Price SrCnt SrCnt1End If
11VBScript If Else Statement
- Syntax If ltconditiongt Then ltlist1 of
operationsgt Else ltlist2 of
operationsgt End If - ExampleIf Hourly1 Then Pay Rate
HoursElse Pay Salary/12End If
12VBScript While Statement
- SyntaxWhile ltconditiongt ltList of
statementsgtWend
13ASP Example Input Form
ltHTMLgt ltHEADgtltTITLEgt Simple ASPlt/TITLEgtlt/HEADgt ltBO
DYgt ltH2gt Buy From Tom lt/H2gt ltFORM
ACTION"Simple2.asp" METHOD"POST"gt Name ltINPUT
TYPE"TEXT" NAME"Name"gt ltPgt We have a special
rate of 1000 per standard model computer. The
down payment is 100 with an interest rate of
12.ltPgt Purchase now? ltINPUT TYPE"CHECKBOX"
NAME"Purchase" VALUE"true" CHECKEDgt ltPgtPreferr
ed Equipment ltBRgt Mac ltINPUT TYPE"RADIO"
NAME"Env" VALUE"Mac" CHECKEDgtltBRgt PC ltINPUT
TYPE"RADIO" NAME"Env" VALUE"PC" gt ltPgt Monthly
Payment ltINPUT TYPE"TEXT" NAME"Payment"gt
ltPgt ltINPUT TYPE"SUBMIT" VALUE"Submit
data"gt ltINPUT TYPE"RESET" VALUE"Clear
data"gt lt/FORMgtlt/BODYgt lt/HTMLgt
14ASP Example Response script
ltHTMLgtltHEADgtltTITLEgtBuy from Tom
Responselt/TITLEgtlt/HEADgtltBODYgt ltH2gtThanks From
Tomlt/H2gt lt Dim Balance, Monthly, Month,
PaymentAmt Response.Write("Welcome to Buy From
Tom, " Request.Form("Name") "! ltPgt") If
Request.Form("Env") "Mac" Then
Response.Write ("We see that you are a fan of Mr.
Jobs ltPgt") Else Response.Write("We see
that you are a fan of Mr. Gates ltPgt") End If
If Request.Form("Purchase") Then
Response.Write("Thanks for your purchase! ltPgt")
Response.Write("Your payment schedule will be
(after downpayment) ltPgt") Balance 900
PaymentAmt CInt(Request.Form("Payment"))
Month 1 While Balance gt
PaymentAmt Monthly 0.01 Balance Balance
Balance - (PaymentAmt-Monthly) Response.Write("Mo
nth " Month " Balance " Balance
"ltBRgt") Month Month 1 Wend If
Balance gt 0 Then Response.Write("Month " Month
" Balance 0 ltBRgt") End If End
If gt lt/BODYgtlt/HTMLgt
15ASP Example Response Page
16Go to next presentation