ASP - Andrew.cmu.edu

Download Report

Transcript ASP - Andrew.cmu.edu

Dynamic HTML Using
Active Server Pages (ASP)
Alberto Espinosa
MIS 45-870
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
1
Static 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. Client’s browser interprets HTML and presents
page to user
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
2
Dynamic 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?
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
3
Dynamic 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
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
4
Client 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
<SCRIPT LANGUAGE = “JavaScript”>
script code …………
</SCRIPT>
More HTML stuff
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
5
Server 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)
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
6
Server Side Scripting (cont’d)
• Embedded scripts in HTML page
HTML code
<%
(marks the beginning of ASP script)
………..……….
ASP script code
………………....
%>
(marks the end of ASP script)
More HTML code
<% more ASP %>
Etc.
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
7
Dynamic 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
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
8
Dynamic HTML with ASP
ASP code on server
HTML code sent to client
<H3>Welcome to my page</H3>
<H2>Here is my product list</H2>
<%
‘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
%>
‘End ASP code
<P>Thank you very much for
inquiring about our products
2/22/00
Same
Dynamically
generated
by ASP
Same
<H3>Welcome to my page</H3>
<H2>Here is my product list</H2>
<P>
<B>Product
Price</B>
<HR>
<P>Hammer ……... $8.50
<P>Pliers ……….… $7.79
<P>Screwdriver ..… $4.50
<P>Power Drill ….. $49.99
<P>Chainsaw …… $95.95
<P>Wrench ……….. $6.50
<P>Thank you very much for
inquiring about our products
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
9
ASP, SQL, Databases, and HTML
Web Server
MS IIS Web Server
SQL Query
ASP
Databases
HTML
Query
Results
Dynamic
HTML
Produced
On-the-Fly
HTML
Request
ASP
Request
HTML doc
Fetched
Client Browser
Internet Explorer
Netscape Navigator
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
10
Server Requirements
• You can’t 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
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
11
Common 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)
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
12
Very 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.)
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
13
Example--ASP on Server (Query)
<% Set conn = Server.CreateObject("ADODB.Connection")
conn.open "orders "
Set rs_customers = Conn.Execute("SELECT clientID, clientName,_
shipAddress, telephone FROM clients") %>
<IMG SRC="music22.gif"><B>Alberto's Music Instruments, Inc.<p>
<TABLE BORDER="0"><B>Customer List</B>
<TR><TH>ClientID</TH> <TH>Client Name</TH> <TH>Shipping
Address</TH> <TH>Telephone</TH></TR>
<% do while Not rs_customers.eof %>
<TR><TD><%= rs_customers.Fields("clientID")
%></TD>
<TD><%= rs_customers.Fields("clientName") %></TD>
<TD><%= rs_customers.Fields("shipAddress")%></TD>
<TD><%= rs_customers.Fields("telephone") %></TD></TR>
<%
rs_customers.MoveNext
loop
Conn.Close %>
</TABLE></BODY></HTML>
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
14
Example--Response to Browser
<IMG SRC="music22.gif"><B>Alberto's Music Instruments, Inc.<p>
<TABLE BORDER="0"><B>Customer List</B>
<TR><TH>ClientID</TH> <TH>Client Name</TH>
<TH>Shipping Address</TH> <TH>Telephone</TH> </TR>
<TR><TD>josee</TD>
<TD>Alberto Espinosa</TD>
<TD>Schenley Park, GSIA Building, #20</TD>
<TD>412-268-3681<BR></TD> </TR>
<TR><TD>sandy</TD>
<TD>Sandra Slaughter</TD>
<TD>5000 Forbes Avenue, Pittsburgh PA 15213</TD>
<TD>412-268-3681<BR></TD> </TR>
etc.
</TABLE></BODY></HTML>
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
15
Example--ASP on Server (Data Input)
<B>Customer Registration</FONT></B><P>
<FORM ACTION=
"http://softrade-11.gsia.cmu.edu/data/customerSubmit.asp"
METHOD="POST" ENCTYPE="x-www-form-urlencoded">
<TABLE>
<TR><TD>Please
<TD><INPUT
</TD></TR>
<TR><TD>Please
<TD><INPUT
</TD></TR>
etc.
</TABLE>
enter a customer ID (4 to 16 characters)</TD>
TYPE="text" SIZE="35" NAME="CustomerID" VALUE=" ">
enter your name</TD>
TYPE="text" SIZE="35" NAME="CustName" VALUE=" ">
<INPUT TYPE="submit" VALUE="Submit"></TD></TR>
</TABLE></FORM></BODY></HTML>
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
16
Example--ASP on Server (Data Input)
<!-- customerSubmit.asp -->
<HTML><BODY><CENTER>
<% Set conn = Server.CreateObject("ADODB.Connection")
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 %>
Your Customer Registration has been processed!<BR>
Thank you very much<BR>
<A HREF="http://softrade-11.gsia.cmu.edu/data/orders.html">
Back to main page</A>&nbsp;&nbsp;&nbsp;
</CENTER></BODY></HTML>
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
17
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
18
IT 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 don’t need to run on IIS (nor ASP)
• But need to feed data to existing ASP scripts
2/22/00
J. Alberto Espinosa -- CMU/GSIA
MIS 45-870
19