Title: Dynamic HTML Using Active Server Pages (ASP)
1Dynamic HTML UsingActive Server Pages (ASP)
- Alberto Espinosa
- MIS 45-870
2Static HTML and the HTTP Protocol
- HTTP ? designed as a doc fetching protocol
- 1. User clicks on URL with HTTP protocol
- 2. Browser requests HTML page to web site
- 3. Server finds/sends HTML page to client as is
- 4. Clients browser interprets HTML and presents
page to user
3Dynamic HTML Overcoming HTTP Shortcomings
- HTML is static text (info) and tags (formatting)
- Corporate information is dynamic
- If info changes ? HTML pages need to change
- How to customize displays for different users?
4Dynamic HTML
- 2 Solutions to Static HTML
- 1. Client side scripting
- Further processing by browser after page is
received - 2. Server side scripting
- Prior processing by web server before page is sent
5Client Side Scripting
- Useful for interactive use with user
- Browser needs to support the scripting language
used - Most popular JavaScript, VB Script
- Embed scripts in HTML page
- HTML stuff
- ltSCRIPT LANGUAGE JavaScriptgt
- script code
- lt/SCRIPTgt
- More HTML stuff
6Server Side Scripting
- Useful to interact with data stored on the server
(databases, images, etc.) - And when centralized processing is needed
- Sever needs to support the scripting language
- Most popular
- CGI ? Perl (Unix)
- ASP ? VB Script or JScript (Windows)
7Server Side Scripting (contd)
- Embedded scripts in HTML page
- HTML code
- lt (marks the beginning of ASP
script) - ...
- ASP script code
- ....
- gt (marks the end of ASP script)
- More HTML code
- lt more ASP gt
- Etc.
8Dynamic HTML with ASP
- 1. Client clicks on URL with .asp file
- 2. Web server notices file extension .asp
- Note Only Windows NT IIS web server supports ASP
- 3. Server then processes .asp file
- 4. Server creates a new HTML file
- 5. Contains all original HTML stuff
- 6. Plus processing results from ASP code
- 7. Dynamically formatted as HTML
- 8. Server sends the new HTML file to client
9Dynamic HTML with ASP
ASP code on server
HTML code sent to client
Same
- ltH3gtWelcome to my pagelt/H3gt
- ltH2gtHere is my product listlt/H2gt
- lt Start ASP code
- Open a database connection
- SQL queries to database
- Copy results to a record set
- Display records one at a time
- Close database connection
- gt End ASP code
- ltPgtThank you very much for inquiring about our
products
ltH3gtWelcome to my pagelt/H3gt ltH2gtHere is my
product listlt/H2gt ltPgt ltBgtProduct
Pricelt/Bgt ltHRgt ltPgtHammer ... 8.50 ltPgtPliers
. 7.79 ltPgtScrewdriver .. 4.50 ltPgtPower
Drill .. 49.99 ltPgtChainsaw 95.95 ltPgtWrench
.. 6.50 ltPgtThank you very much for inquiring
about our products
Dynamically generated by ASP
Same
10ASP, SQL, Databases, and HTML
Web Server MS IIS Web Server
HTML
ASP
Databases
Client Browser Internet Explorer Netscape
Navigator
11Server Requirements
- You cant do ASP on Andrew
- ASP requires an MS Windows environment
- NT Server with Internet Information Server
- NT Workstation with Peer Web Services (10-user
connection limit) - Win95/98 with Personal Web Server
12Common Uses of ASP
- Register as a client (insert a record in
database) - Products services listing (query database)
- Place orders (inserting records in database)
- Track order status (query database)
- Tech support (query a knowledge base)
- Fill out a survey (insert record(s) in database)
13Very Common
- Feed data to an ASP script using HTML forms
- This is typically what the Submit button does
- HTML forms contain items data with field names
- Which are passed to ASP scripts for processing
- Often used to embed an SQL command
- To query a database (product list, etc.)
- Or to insert records in a database (orders, etc.)
14Example--ASP on Server (Query)
- lt Set conn Server.CreateObject("ADODB.Connectio
n") - conn.open "orders "
- Set rs_customers Conn.Execute("SELECT
clientID, clientName,_ - shipAddress, telephone FROM clients") gt
- ltIMG SRC"music22.gif"gtltBgtAlberto's Music
Instruments, Inc.ltpgt - ltTABLE BORDER"0"gtltBgtCustomer Listlt/Bgt
- ltTRgtltTHgtClientIDlt/THgt ltTHgtClient Namelt/THgt
ltTHgtShipping Addresslt/THgt ltTHgtTelephonelt/THgtlt/TRgt
- lt do while Not rs_customers.eof gt
- ltTRgtltTDgtlt rs_customers.Fields("clientID")
gtlt/TDgt - ltTDgtlt rs_customers.Fields("clientName"
) gtlt/TDgt - ltTDgtlt rs_customers.Fields("shipAddress
")gtlt/TDgt - ltTDgtlt rs_customers.Fields("telephone")
gtlt/TDgtlt/TRgt - lt rs_customers.MoveNext
- loop
- Conn.Close gt
- lt/TABLEgtlt/BODYgtlt/HTMLgt
15Example--Response to Browser
- ltIMG SRC"music22.gif"gtltBgtAlberto's Music
Instruments, Inc.ltpgt - ltTABLE BORDER"0"gtltBgtCustomer Listlt/Bgt
- ltTRgtltTHgtClientIDlt/THgt ltTHgtClient Namelt/THgt
- ltTHgtShipping Addresslt/THgt ltTHgtTelephonelt/THgt
lt/TRgt - ltTRgtltTDgtjoseelt/TDgt
- ltTDgtAlberto Espinosalt/TDgt
- ltTDgtSchenley Park, GSIA Building, 20lt/TDgt
- ltTDgt412-268-3681ltBRgtlt/TDgt lt/TRgt
- ltTRgtltTDgtsandylt/TDgt
- ltTDgtSandra Slaughterlt/TDgt
- ltTDgt5000 Forbes Avenue, Pittsburgh PA
15213lt/TDgt - ltTDgt412-268-3681ltBRgtlt/TDgt lt/TRgt
- etc.
- lt/TABLEgtlt/BODYgtlt/HTMLgt
16Example--ASP on Server (Data Input)
- ltBgtCustomer Registrationlt/FONTgtlt/BgtltPgt
- ltFORM ACTION
- "http//softrade-11.gsia.cmu.edu/data/custom
erSubmit.asp" - METHOD"POST" ENCTYPE"x-www-form-urlencoded
"gt - ltTABLEgt
- ltTRgtltTDgtPlease enter a customer ID (4 to 16
characters)lt/TDgt - ltTDgtltINPUT TYPE"text" SIZE"35"
NAME"CustomerID" VALUE" "gt - lt/TDgtlt/TRgt
- ltTRgtltTDgtPlease enter your namelt/TDgt
- ltTDgtltINPUT TYPE"text" SIZE"35"
NAME"CustName" VALUE" "gt - lt/TDgtlt/TRgt
- etc.
- lt/TABLEgt
- ltINPUT TYPE"submit" VALUE"Submit"gtlt/TDgtlt/TRgt
- lt/TABLEgtlt/FORMgtlt/BODYgtlt/HTMLgt
17Example--ASP on Server (Data Input)
- lt!-- customerSubmit.asp --gt
- ltHTMLgtltBODYgtltCENTERgt
- lt Set conn Server.CreateObject("ADODB.Connectio
n") - conn.open "orders
- customerId Request.Form("customerId")
- custName Request.Form("custName") . etc.
- Set rs Conn.Execute("INSERT INTO Clients
(ClientID, CustName, _ - etc. VALUES ('" customerID "', '"
customerName "', _ - '" shippingAddress "', '" phone "')
") - Conn.Close gt
- Your Customer Registration has been
processed!ltBRgt - Thank you very muchltBRgt
- ltA HREF"http//softrade-11.gsia.cmu.edu/data/orde
rs.html"gt - Back to main pagelt/Agtnbspnbspnbsp
18(No Transcript)
19IT Exercise III
- A restaurant food delivery service company
- Participant restaurants subscribe to service
- Company developed a web site using ASP to let
- 1. Restaurants subscribe and enter menu items
- 2. Customers place orders
- Web server runs on Windows NT with IIS
- Participant restaurants need to produce their
HTML pages with order forms - Which dont need to run on IIS (nor ASP)
- But need to feed data to existing ASP scripts