Title: Website Development
1Website Development Management
MIS 3353 -- Fall 2002
- Server-Side Scripting Using Active Server Page
Technology
Instructor John Seydel, Ph.D.
2Student Objectives
- Create server-side confirmation pages
- Discuss what happens when browser and server
interact for web page delivery - Differentiate among the various VBScript data
subtypes - Use appropriate variable naming conventions
- Summarize useful VBScript string, date, math, and
conversion functions - Compare and contrast subroutines and functions
- Use If . . . Then . . . Else contruct for
branching - Be familiar with Select . . . Case construct
applications - Use For . . . Next and Do While contructs for
looping - Understand the use of the Response and Request
objects for basic ASP output and input
3First, Some Administrative Stuff
- Exam 2
- Grading
- Part 1 (written portion)
- 67 points possible
- Highest raw score 64
- Raw scores adjusted
- Minimum 53 (my work)
- Scores above raised (split the difference)
- Part 2 (online portion)
- 33 points possible
- Everyone who tried received full points for Part
2 - Return exams (and recent quiz)
- Questions concerning homework?
4A Look at the Guestbook Form Handler
- Values collected by guestbook controls
- Text box txtName
- Radio buttons optGender
- Select box cmbAge
- Check boxes chkFTStudent, chkFTJob, chkBurnout
- Basic form handler
- Simply confirms what was sent
- Starts with an HTML page with blanks left in it
for data - Needs then to access data sent as part of Form
collection - Use Request.Form()
- Assign results to variables
- Then fills in the blanks within the HTML page
using Response.Write - Coming soon updating and accessing the database
5Some Things to Note About the GuestBook Form
Handler
- Look at complete code
- Option Explicit
- Forces variables to be declared
- Must be very first statement of code (before XML
declaration) - Generally optional where scripting takes place
recommendation - Document head preliminary processing
- Within document on-demand processing
- Could have used Response.Write to have the server
write all or part of the HTML (recommended by
text) - Recommendation for this class write as much as
possible of the HTML without relying on the
server to write it - More intuitive because of familiarity with HTML
- Works better when HTML editor is being used
6Input and Output with ASP
- Two important server objects are involved here
- Request
- Response
- These objects have numerous uses via their
- Properties
- Methods (i.e., functions and subroutines)
- For now lets consider only input/output
- Getting information (input) Request object
- Access the Form, QueryString, or ServerVariables
collections (collections are like arrays) - Gathers data from those collections
- Sending information (output) Response object
- Call the Write method (a subroutine)
- Writes information to the web page being sent to
client
7What Happens When You View a Web Page?
- Consider figure on p. 60 (or p. 16 in XHTML text)
- Two ways to request resources
- Click on a link
- Type a URL into address bar
- HTTP request is then sent to server at designated
URL - Includes header info
- Requests file
- Server processes file
- If htm extension, then just sends file with
response - If asp extension, then script is processed first
- Server then returns HTTP response
- Includes header info
- Contains files (HTML and others, e.g., images)
8HTTP Request Example
- Request
- GET/index.html?namejuliesmithID12234
- /HTTP/www.astate.edu
- /HTTP1.1
- Header
- Useragent IE 5.0
- Accept /
- Date 10/24/02
- Body
- (empty)
9HTTP Response Example
- Response
- HTTP1.1/200
- Header
- Server IIS 50
- Date 10/24/02
- Body
- lthtmlgt
- . . .
- lt/htmlgt
10ASP and VBScript
- ASP is a server-side processing technology by
Microsoft - Will interpret programming instructions in
several languages - JScript (MS implementation of JavaScript)
- VBScript the de facto language for ASP
- Others
- ASP code is delimited by lt and gt
- VBScript
- Uses same syntax as VB
- Most of the data types and functionality for VB
are available to VBScript - Therefore, a good reference for VBScript is any
text on VB
11Before Going Further, Lets Consider Data Subtypes
- VBScript automatically determines data subtype
based upon variable contents - Typical subtypes well be using
- Numeric
- Integer
- Long
- Double
- String
- Date
- Boolean
- Why worry?
- We need to be aware of data subtype in order to
manipulate (math operations, string processing, .
. . ) - Use the appropriate conversion functions
12Variable Naming Conventions
- Variable names based upon data type
- First three characters in lower case
- Words starting in upper case
- Common names (see table on page 137)
- String (e.g., strFirstName)
- Integer (e.g., intAge)
- Double (e.g., dblBMI)
- Long (e.g., lngStatePopulation)
- Boolean (e.g., blnHealthy)
- Date (e.g., datPurchase)
13Data Conversion Functions
- Form data will often be interpreted by VBScript
as text and must converted for arithmetic to be
performed - Also data from a database can be of numerous
types and must often be converted - For best results, use conversion functions (see
p. 145) - CStr()
- CInt()
- CLng()
- CDbl()
- FormatCurrency()
- Note just naming a variable per the
conventions, doesnt make the data contained
conform to the name - Example intAmount More money!
- Doesnt convert to integer
14A Little Bit on Functions, Subroutines,
Arguments
- Arguments (called parameters) are the values
brought into and used in the subprocedure - Syntax for subprocedures
- Functions (return values)
- Defining FunctionName(arg1,arg2, . . .)
- Calling Variable FunctionName(arg1,arg2, . .
.) - Example strTotalPrice FormatCurrency(dblPrice,
2) - Subroutines (dont return values)
- Defining SubroutineName(arg1, arg2, . . .)
- Calling Call SubroutineName(arg1, arg2, . . .)
- Example Call Response.Write(strName)
15A Digression Some Shortcuts
- Note equivalence
- Call Response.Write(strName)
- Response.Write(strName)
- Response.Write strName
- If only one statement is involved the following
are also equivalent - lt Response.Write strName gt
- lt strName gt
- If data are coming only from a single source or
multiple sources with no duplicate names, the
following are equivalent - Request.Form(txtName)
- Request(txtName)
16Intrinsic Functions
- Many built-in (intrinsic) functions come as part
of VB (and VBScript) - Some categories are
- Date Time
- String Manipulation
- Numeric
- Its important to be familiar with these
- That they exist
- Where to find information about them
17Handy Date/Time Functions
- Time
- Date
- Now -- returns both date and time
- Day(date) -- returns day portion of date string
- Month(date) -- returns month portion of date
string - Year(date) -- returns year portion of date string
- Weekday(date) -- returns day (1-7) of the week
- WeekdayName(number) -- returns day (e.g., Monday)
for given weekday (1-7) - MonthName(number) -- returns month (e.g., March)
for given month number (1-12) - DateDiff(date1,date2) -- returns number of days
difference - DateAdd(date,number) -- returns new date
18String Functions
- Some of the more useful ones
- InStr(search,target) -- returns starting position
- Len(string) -- returns length of string
- LCase(string) -- converts case
- LTrim(string) -- trims blanks at left
- Trim(string) -- trims blanks at both ends
- String(n,character) -- returns n characters
- Left(string,n) -- returns left n characters
- Mid(string,x,n) -- returns n characters starting
at x - An example the original guestbook form handler
19Math Functions
- Ones well likely use
- Rnd -- needs to be preceded by call to Randomize
- Int(x) -- truncates beyond decimal point
- Round(x) -- rounds to nearest whole number
- Some of the others that exist
- Exp(x)
- Log(x)
- Sqr(x)
- Fix(x)
- . . .
20Control Structures in VBScript
- Recall the framework weve been dealing with
- Sequence
- Selection (per the text, branching)
- Looping
- Now, (per the text) add jumping
- Often a form of selection
- Involves subprocedures
- Functions
- Subroutines
21Branching Structures
- VBScript
- If . . . Then . . . Else
- Select . . . Case
- Similar in usage to their JavaScript counterparts
22Syntax for If . . . Then . . . Else
- Consider original guestbook form handler
(determining Mr./Ms prefix) - VBScript syntax
- If condition Then
- . . . what to do if true . . .
- Else
- . . . What to do if false . . .
- End If
- Compare to JavaScript
- if (condition)
- . . . what to do if true . . .
- else
- . . . What to do if false . . .
23Syntax for Select . . . Case
- Use instead of If . . . Then . . . Else when many
possible branches - VBScript
- Select Case varname
- Case value1
- What to do
- Case value2
- What to do
- . . .
- Case Else
- What to do
- End Select
- Compare with JavaScript
- switch (varname)
-
- case value1 what to do
- case value2 what to do
- . . .
- default what to do
24Looping Structures
- Enable repetitive ifthenelse processing
- Several options exist well be using
- For . . . Next loops
- Do . . . While loops
- As with JavaScript,
- Automatic incrementing takes place with For loop
- Must have something to cause Do loop to terminate
- Consider form processing of records from a
database (e.g., guestbook database)
25For . . . Next Loops
- VBScript
- For counter startvalue To stopvalue Step
increment - . . . statements . . .
- Next
- Compare with JavaScript
- for (start terminal condition step)
- . . . statements . . .
26Do . . . While Loops
- VBScript
- Do While condition
- . . . statements . . .
- Loop
- Compare with JavaScript
- while (condition)
- . . . statements . . .
27Review/Demo of ASP Application Development
- Must be tested on a server
- Actual server (AITP), running IIS
- Possibly local IIS if running Win2000
- Recommended process
- Write code locally
- Upload
- Test
- Modify locally
- Upload new version
- Test
- Repeat as necessary
28Student Objectives
- Create server-side confirmation pages
- Discuss what happens when browser and server
interact for web page delivery - Differentiate among the various VBScript data
subtypes - Use appropriate variable naming conventions
- Summarize useful VBScript string, date, math, and
conversion functions - Compare and contrast subroutines and functions
- Use If . . . Then . . . Else contruct for
branching - Be familiar with Select . . . Case construct
applications - Use For . . . Next and Do While contructs for
looping - Understand the use of the Response and Request
objects for basic ASP output and input
29Appendix
30GuestBook Confirmation Plain XHTML with Blanks
- ltheadgt
- lttitlegtGuest Book Response for Suzy
Studentlt/titlegt - lt/headgt
- ltbodygt
- lth1 align"center"gtGuestbook Confirmationlt/h1gt
- lth3gtHere's the information you gave uslt/h3gt
- ltulgt
- ltligtName ltemgt xxx lt/emgtlt/ligt
- ltligtGender ltemgt xxx lt/emgtlt/ligt
- ltligtAge ltemgt xxx lt/emgtlt/ligt
- ltligtFull-time student ltemgt xxx lt/emgtlt/ligt
- ltligtWorking full-time ltemgt xxx lt/emgtlt/ligt
- ltligtGoing to school and working ltemgt xxx
lt/emgtlt/ligt - lt/ulgt
- lt/bodygt
31GuestBook Confirmation Getting Data
- ltheadgt
- lttitlegtGuest Book Response for Suzy
Studentlt/titlegt - lt
- Dim strName,strAge,strGender,strFTStu,strFTWork,
strBurnout - strGender Request.Form("optGender")
- strName Request.Form("txtName")
- strAge Request.Form("cmbAge")
- strFTStu Request.Form("chkFTStudent")
- If strFTStu ltgt "yes" Then strFTStu "no"
- strFTWork Request.Form("chkFTJob")
- If strFTWork ltgt "yes" Then strFTWork "no"
- strBurnout Request.Form("chkBurnout")
- If strBurnout ltgt "yes" Then strBurnout "no"
- gt
- lt/headgt
32GuestBook Confirmation Displaying Data
- ltulgt
- ltligtName ltemgtlt Response.Write strName
gtlt/emgtlt/ligt - ltligtGender ltemgtlt Response.Write strGender
gtlt/emgtlt/ligt - ltligtAge ltemgtlt Response.Write strAge
gtlt/emgtlt/ligt - ltligtFull-time student
- ltemgtlt Response.Write strFTStu gtlt/emgt
- lt/ligt
- ltligtWorking full-time
- ltemgtlt Response.Write strFTWork gtlt/emgt
- lt/ligt
- ltligtGoing to school and working
- ltemgtlt Response.Write strBurnout gtlt/emgt
- lt/ligt
- lt/ulgt
33Objects
- Characteristics
- Have properties (attributes that describe them)
- Do things
- Methods (i.e., behaviors or subprograms)
- Functions (return values)
- Subroutines
- Triggered by
- Events (e.g., onMouseOver)
- Direct calls
- Where do they come from
- Built in
- Browser objects (e.g., window)
- JavaScript objects (e.g., Math)
- ASP objects (e.g., Response)
- Need reference for properties and methods
- User-defined