190 likes | 516 Vues
Dynamic HTML Using Active Server Pages (ASP). Alberto Espinosa MIS 45-870. 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”
E N D
Dynamic HTML UsingActive Server Pages (ASP) Alberto Espinosa MIS 45-870 J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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 J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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? J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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 J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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 J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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) J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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. J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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 J. Alberto Espinosa -- CMU/GSIA MIS 45-870
Dynamic HTML with ASP ASP code on server HTML code sent to client 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 <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 Dynamically generated by ASP Same J. Alberto Espinosa -- CMU/GSIA MIS 45-870
SQL Query Query Results HTML Request Dynamic HTML Produced On-the-Fly ASP Request HTML doc Fetched ASP, SQL, Databases, and HTML Web Server MS IIS Web Server ASP HTML Databases Client Browser Internet Explorer Netscape Navigator J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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 J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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) J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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.) J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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> J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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> J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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 enter a customer ID (4 to 16 characters)</TD> <TD><INPUT TYPE="text" SIZE="35" NAME="CustomerID" VALUE=" "> </TD></TR> <TR><TD>Please enter your name</TD> <TD><INPUT TYPE="text" SIZE="35" NAME="CustName" VALUE=" "> </TD></TR> etc. </TABLE> <INPUT TYPE="submit" VALUE="Submit"></TD></TR> </TABLE></FORM></BODY></HTML> J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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> </CENTER></BODY></HTML> J. Alberto Espinosa -- CMU/GSIA MIS 45-870
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. Customersplace 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 J. Alberto Espinosa -- CMU/GSIA MIS 45-870