Title: BMIS 289: Spring 2001
1BMIS 289 Spring 2001
- ASP FundamentalsJanuary 29, 2001
2Program 1 Algorithm
- Input the stock transaction details
- HTML Form
- Get data from input form
- Calculate results of transaction
- TotalCost PurchasePrice n
- Return TotalCost (ClosingPrice n)
- (where n is the number of shares bought)
- Output the results
- Echo form inputs
- Output TotalCost and Return
3Program 1 - Code
- HTML Input Form
- Input.htm
- Process.asp
- Program header comment
- Declare and initialize variables
- Calculate the total cost of the purchase and its
return - Output
4Virtual Directories
- A physical directory is an actual path on a
servers hard drive - C\inetpub\wwwroot\mywebsite
- A virtual directory points to a physical
directory - http//www.webserver.com/mywebsite ?
C\inetpub\wwwroot\mywebsite - So when a browser sends a request to the web
server for http//www.webserver.com/mywebsite/page
.asp the virtual directory we setup knows to look
in c\inetpub\wwwroot\mywebsite for the file
page.asp
5Setting Up A Virtual Directory With Personal Web
Server
- Launch Personal Web Server
- Launch the Personal Web Manager
- Usually this is an icon in the system tray of the
taskbar (lower right-hand corner). - Select Advanced and then click Add
- Browse to the directory you want this virtual
directory to point to, then enter an Alias for
it. - Read and Scripts permission is usually adequate.
6How The Web Works
- The web is built on the client-server
relationship - Server hosts software, data, processes,
information, etc. - Clients access these servers to get at this
stuff. - All these interconnected systems allow universal
access. - The web also operates under several protocols
(rules for communicating), the most important
ones being TCP/IP and HTTP
7TCP/IP
- TCP Transmission Control Protocol
- Responsible for packaging data up before its
sent over a network and then unpacking it and
reassembling it properly on the receiving end. - IP Internet Protocol
- Responsible for getting the data to where it
needs to go (i.e., how to get from A to B).
8HTTP
- Hypertext Transfer Protocol
- An application protocol that is a specific type
of Internet protocol. It focuses on the
addressing and delivery of files (text, sound,
video, etc). - HTTP Request
- Message going from Browser ? Server
- HTTP Response
- Message going from Server ? Browser
9HTTP Request (pg. 60)
- Request Line
- Details about the request itself.
- HTTP Header
- Misc. meta information (usually about the client
making the request). - HTTP Body
- Any data the client is sending to the server
(like form input fields).
10HTTP Request Request Line
- How much information the client needs and how
much information is being sent. - Method Types
- GET obtain data at a particular URL. Any input
the user entered is appended to the URL. - POST Data will be sent to the server as part of
the HTTP request.
11HTTP Request HTTP Header
- The HTTP Header contains details about the client
and other general configuration information. - Types of information found in HTTP Header
- General info about client or server.
- Entity information about data being sent between
client and server. - Request information about client configuration
and what kind of documents it accepts.
12HTTP Request HTTP Body
- In an HTTP Request the HTTP Body section is
usually empty, unless we used the POST method
when sending our HTTP Request.
13HTTP Response Response Line
- Contains only two bits of information
- HTTP version number
- Request code that indicates success or failure of
the request. - HTTP Error 404 is one of the most common HTTP
Request codes you will run into on the Internet. - The 404 error indicates that the document you
were looking for was not located where the
request thought it was.
14HTTP Response HTTP Header
- Similar to the Request HTTP Header
- Information falls into three types
- General Information about client or server.
- Entity information about data being sent between
client and server. - Response information about the server
15HTTP Response HTTP Body
- If the Request is successful then the resulting
HTML code is sent back in the HTTP Body.
16Script Languages
- The current version of ASP is not a typical
compiled programming language. - It is a script language.
- Code written in a script language is processed
dynamically by a script engine which interprets
the code and outputs the results. - The default ASP script language is VBScript,
though other script languages like JScript can be
used.
17Server-Side Client-Side Script
- Server-Side Script
- Code is executed on the server.
- Since we can control the server that processes
the script we know that all browsers will get the
same results back. - Can be slower to execute than client-side script.
- Client-Side Script
- Code is executed on the client browser.
- Usually is faster than server-side.
- Different browsers produce different results with
same code (Browser Dependent).
18Scripting Examples
- Server-side Inline lt gt
- Script engine writes the results of the code
directly into the HTML stream at the positions we
indicate. - Server-side ltscript runatservergt
- Script engine appends results to the end of the
HTML stream. - Client-side - ltscript runatclientgt
- ASP engine ignores this code and will let the
browser process it. - JavaScript is the most popular client-side
scripting language. - Order of execution examples on pg. 80 in your
book.
19Objects Components
- Objects are packages of related code that provide
certain information (properties) and
functionality (methods) to programmers - Components are collections of certain objects.
- ASP has several pre-built (intrinsic) objects and
components for programmers to use. - Programmers could also write their own objects
and components to supplement ASP. - These are often known as custom or third
party components.
20Intrinsic ASP Objects
- Request
- Used to deal with the requests users make for web
pages. This request could be anything from an
HTML form to a simple URL. - Example Request.Form(FormField)
- Response
- Deals with web servers response back to the
client. - Example Response.Write Hello web browser!
- Server
- Functions only the web server can perform, like
setting the amount of time a user can be idle.
21Intrinsic ASP Objects Cont.
- Application
- A web application is considered a collection of
related ASP pages and other files. The
application object can be used to manipulate
these web applications. - Session
- Every time an individual user arrives at our web
site the web server generates a unique session to
reference them. We use the session object to
manipulate and retrieve information related to
that session.
22Some Intrinsic ASP Components
- Ad Rotator
- Manage banner advertisements
- Browser Capabilities
- Determine what kind of browser a user visiting
the site is using. - Microsoft Data Access Components (MDAC)
- Set of objects for accessing and manipulating
databases.
23Quick Review Of The Basics
- Input
- Create HTML form.
- Send data to an asp page for processing.
- Process
- Get the data using Request.Form and store the
values in variables. - Manipulate data in variables (perform arithmetic,
sort data, save data in offline storage). - Output
- Write the results of the process to the HTTP Body
(as HTML) using Response.Write
24Generating HTML
- So far we have seen how we can output values a
user has entered into a form, using
Response.Write - But Response.Write doesnt have to output only
what the user has entered and the values of any
processes performed On that input. - We can use ASP to generate HTML code itself (code
generates code).
25Why Generate HTML?
- Aesthetic reasons primarily.
- HTML is a presentation language, so using ASP to
dynamically generate HTML code can make the
resulting page look more pleasing to the eye. - Using HTML elements like tables to format output
from a database query can make the information
easier to interpret and read. - Example (code on our class web site)
26HTML Table
- Useful for presenting information in a clean,
logical manner. - Good way to format the layout of a page.
- Base tag lttablegt
- Row tag lttrgt
- Cell tag lttdgt
27ltTABLEgt Attributes
- Width pixel or value (percentage of the
browser screen) - Border pixel value
- Bgcolor red, blue, etc or rgb values
(FFFFFF white) - Cellpadding pixel value, the amount of padding
space around text in individual cells. - Cellspacing pixel value, the amount of spacing
between individual cells.
28ltTRgt Attributes
- Bgcolor color name or rgb value.
- Align CENTERLEFTRIGHT how text in the rows
cells is horizontally aligned. - Valign TOPMIDDLEBOTTOMBASELINE how text in
the rows cell is aligned vertically.
29ltTDgt Attributes
- Bgcolor color name or rgb value
- Width pixel value or
- Height pixel value
- Valign, Align same as ltTRgt tag.
- Colspan number of columns above or below a cell
should overlap. - Rowspan number of rows the cell should overlap.
30HTML Table Example
lttable border1gt lttrgt lttd colspan2gtcell 1,
row 1lt/tdgt lttd rowspan2gtcell 2, row 1lt/tdgt
lt/trgt lttrgt lttdgtcell 1, row 2lt/tdgt
lttdgtcell 2, row 2lt/tdgt lt/trgtlt/tablegt
Renders As
31Variables
- A variable is simply a slice of computer memory
that a programmer names in order to reference in
their code later. - ExampleDim myVarmyVar 5
32Data Types
- A data type indicates what kind of information a
variable is holding, such as an integer, a
floating point number, a text string, or a single
character. - VBScript does not have native data types. By
default all variables in VBScript are of the
Variant data type. - A variant can hold any type of data. VBScript
automatically determines what type of data is
located in a variable of the variant data type. - However, we can also explicitly tell VBScript
what data type a particularly variable is using
conversion (in case the Script Engine guesses
wrong when interpreting it).
33Numeric Types
- Integer whole numbers
- 32,767 to 32,768
- Byte small range of integers
- 0-255
- Useful for basic arithmetic
- Long a larger integer
- 2,147,483,647 to 2,147,483,648
- Double very accurate floating point precision
- Currency
- 922,337,203,685,477.5807 to -922,337,203,685,477.5
808
34Other Types
- String holds text
- Examples Hello, 123, July 4, 1776,
12.32 - Date holds dates and times
- Boolean only two possible values (TRUEFALSE)
- Null literally nothing. A zero or an empty
string () are not null, those are something. A
null is nothing. - Empty variables that have yet to be assigned are
called empty, or uninitialized.
35Data Type Conversion Functions
- Example
- Dim PricePerSharePricePerShare
Request.Form(PPS)PricePerShare
Ccur(PricePerShare) - Data Type Conversion Functions
- Currency Ccur()
- Integer Cint()
- Double Cdbl
- String Cstr()
- Others listed on pg. 145
36Declaring Variables
- Declaring
- Dim VariableName
- lt Option Explicit gt
- By default ASP allows us to declare variables
implicitly (i.e., by just using them). - Using this directive requires us to explicitly
declare them first. This helps in debugging code. - Make sure this is the first line of code on all
your ASP pages. - We will be using Option Explicit on ALL programs
from now on.
37Variable Naming
- Rules for naming variables
- Max 255 characters
- Must begin with a letter (e.g., Dim 1abc is
illegal) - No spaces
- Some symbols are illegal, best to only use a
combination of letters, digits, and the - or
_ characters when naming variables. - Cannot used reserved words
- Dim dim is illegal
38Variable Naming Tips
- Be meaningful
- EmployeeBDate is more meaningful than Bdate
- Dont abbreviate too much
- Use comments to explain variable meaning (where
appropriate)!!! - Hungarian Notation
- Prefacing variable name with its data type
- intNum, strName, curPrice, dblPercent
- Pg. 137
- Not required in this class
39Initializing Variables (i.e., putting values in
them)
- We use the assignment operator to place a value
into a variable - TodaysTemp 31.5
- How different types of data are placed into
variables - String WelcomeMsg hello
- Number TodaysTemp 31.5
- Date IndpDay July 4, 1776
- Time LunchTime 12.00
40Arithmetic
- Addition, Subtraction, Multiplication, Division
operators - , -, , /
- Exponents
- NumSquared 102
- Negation
- NegativeNum -6
- Modulus (get the remainder only)
- Remainder 10 MOD 7
- Order of Operations
- P.E.M.D.A.S.
- Start in innermost parenthesis and work from left
to right performing exponents, multiplication
division, and addition subtractions. Then move
to next innermost parenthesis and work from left
to right again.
41String Fundamentals
- Concatenation
- Appending one string on to the end of another
- ExampleDim FirstName, LastName,
FullNameFirstName JaneLastName
SmithFullName FirstName LastName - The variable FullName now contains the string
Jane Smith.
42String Fundamentals Cont.
- Trim remove space characters from certain
positions in a string. - Trim() remove from front and back
- Rtrim() remove from right
- Ltrim() remove from left
- Length find number of characters in string
- Len()
- Dim StringSize, MyNameMyName
ColinStringSize Len(MyName) - StringSize is 5 (i.e., there are 5 characters in
the string Colin)
43String Fundamentals Cont
- Case conversion change the case of a string
- UCase(), LCase()
- Dim LowerCaseStringLowerCaseString abc---
outputs ABCResponse.Write UCase(LowerCaseString
) - Find a particular word in a string
- InStr(StringVariableToSearch, Text to search
for) - SearchStr 123abc--- outputs
4Response.Write InStr(SearchStr, abc) - abc starts at character 4 in the string
123abc
44String Fundamentals Cont.
- Removing the ends of a string
- Left(string, number_of_characters)
- Right(string, number_of_characters)
- Example
- StrVar 123abc--- outputs 123Response.Write
Left(StrVar, 3) - Remove the middle of a string
- Mid(string, start, num_chars_to_extract)
- StrVar 123abc--- outputs 123aResponse.Wri
te Mid(StrVar, 1, 4)
45Constants
- A constant is a variable whose value never
changes during the execution of a program. - Constants are a good way to represent values that
seldom change, like the freezing point of water,
or a phone number. - Use ALL UPPERCASE letters to name constants
- Example
- Const WASHINGTON_POSTCODE WA
46Program 2
- TextArea a text box in which large amounts of
text can be entered. - lttextarea nametxtarea rows5 cols25gtEnter your
data herelt/textareagt - Mailto launches users email application when
clicked with an email address preloaded. - lta hrefmailtocfukai_at_gonzaga.edugtEmail Melt/agt
- Listbox
- ltselect namelistbox1 size3gt ltoptiongtvalue1lt/opt
iongt ltoptiongtvalue2lt/optiongt
ltoptiongtvalue3lt/optiongtlt/selectgt