6afd0bdc16ca8828ce17da19870502c2.ppt
- Количество слайдов: 30
Web programming Cristian Estan – guest lecture in CS 640 November 13 2007
The web as a platform for applications Feature Web app. Desktop app. Graphics Strong Unlimited User interaction Strong Unlimited Network usage High Varies Accessible from Any computer Where installed Upgrade cost Update servers Update desktop Data backup cost Backup servers Backup desktop Popularity Increasing Dominant
Most programs are event-oriented A naïve view n Structure of program n Read input n Perform computation n Produce output n The program may use libraries written by others A realistic view n Structure of program n Wait for events n Find appropriate method for handling the event n Handle the event n Repeat n Often you just add new events and handlers to an existing program
Overview n Web documents n Server-side programming n Client-side programming n Web services
Hyper. Text Markup Language n Disagreement about HTML’s role n Only give the content and structure of the document, leave visualization to the browser n Browsers vary (graphical, text based, mobile devices) User preferences vary (some people like larger fonts) n Environment varies (screen sizes, fonts available, etc. ) n But authors want to control what the document looks like n Trend towards separating content from presentation n Cascading Style Sheets – presentation information only n HTML documents contain little formatting n
Current state of the standards n In the 90 s browser wars (IE vs. Netscape) were driving the evolution of HTML n Non-standard extensions used by pages lead to lock-in n W 3 C (World Wide Web Consortium) sets standards n Last HTML standard 4. 01 (December 1999) n XHTML 1. 0 new XML-based format n XML (extensible markup language) – focuses on semantics and is used as general purpose format for structured data n A document called DTD or XML Schema defines what tags and attributes are allowed in an XML document
<TITLE>Bucky Badger’s web page</TITLE> <BODY> <H 1>Welcome to Bucky's web page</H 1> <IMG SRC="bucky. gif"> <P>I am Bucky, the mascot for University of Wisconsin athletics. Please visit <A HREF="http: //www. uwbadgers. com/football/index. html"> the web page of our football team</A> and <A HREF="http: //www. uwbadgers. com/basketball/index. html"> the web page of our basketball team</A>. </BODY>
A valid web page <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> <html> <head> <title>Bucky Badger’s web page</title> </head> <body> <h 1>Welcome to Bucky's web page</h 1><!-- Users don’t see this comment. --> <img src="bucky. gif" alt="A picture of Bucky" /> <p>I am Bucky, the mascot for University of Wisconsin athletics. Please visit <a href="http: //www. uwbadgers. com/football/index. html"> the web page of our football team</a> and <a href="http: //www. uwbadgers. com/basketball/index. html"> the web page of our basketball team</a>. </p> </body> </html>
About forms n Forms are the traditional way for users to send information to a web server n n n The user fills out fields in the browser The user submits the form http carries the user input to the web server A server side program processes the user data The server sends a reply document to the client
<h 3>Search form</h 3> <form method="get“ action="http: //www. googlesyndicatedsearch. com/u/univwisc"> <p>What are you looking for? <input type="text" name="q" id="search. Text" value="Your search terms. . . " /> <input type="hidden" name="hl" value="en" /> <input type="hidden" name="ie" value="ISO-8859 -1" /> <input type="submit" id="search. Button" value="Search UW-Madison" /> </p></form>
Overview n Web documents n Server-side programming n Client-side programming n Web services
Server side programming n Short history n CGI – separate programs launched by web server n They produce an HTML document as output n They receive arguments as input n Strong isolation, bad performance n Programs embedded inside web page (php, ASP, JSP) n Program executed inside web server process n Separate “code-behind” file for the code (ASP. NET) n What are dynamic pages used for? n Personalizing based on user identity n Interacting with databases (e. g. on-line banking) n Web applications (e. g. web based email) n Separate database keeps persistent data
“Lifecycle” of static web page Web server machine HTTP request Server data URL Server code Request HTML file Web client HTTP response File system
Lifecycle of ASP. NET webpage Web server machine HTTP request Server data Server code Request URL Web client . aspx file codebehind HTTP response HTML snippets Objects representing this web page File system
Page with database interaction Web server machine HTTP request Server data Server code Request URL Web client . aspx file codebehind HTTP response Database SQL interaction HTML snippets Objects representing this web page File system
Trivial ASPX File <%@ Page Language="C#" Auto. Event. Wireup="true" Code. File="Stub. aspx. cs" Inherits="Stub" %> <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> <html xmlns="http: //www. w 3. org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form 1" runat="server"> <div> <asp: Label ID="lbl. Time" runat="server" /> </div> </form> </body> </html>
Trivial Code Behind File using System; using System. Data; using System. Configuration; using System. Collections; using System. Web. Security; using System. Web. UI. Web. Controls; using System. Web. UI. Web. Controls. Web. Parts; using System. Web. UI. Html. Controls; public partial class Stub : System. Web. UI. Page { protected void Page_Load(object sender, Event. Args e) { lbl. Time. Text = Date. Time. Now. To. Long. Time. String(); } }
Output from Trivial Page <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> <html xmlns="http: //www. w 3. org/1999/xhtml" > <head><title> Untitled Page </title></head> <body> <form name="form 1" method="post" action="Stub. aspx" id="form 1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/stuff" /> </div> <span id="lbl. Time">2: 52: 13 PM</span> </div> </form> </body> </html>
Overview n Web documents n Server-side programming n Client-side programming n Web services
Why is Java. Script important? n Web pages can contain Java. Script programs executed inside the browser n n Supported by all major browsers n Microsoft’s version called Jscript (the language is the same) User may disable Java. Script due to security fears n This is default for some newer versions of Internet Explorer n Client-side programming important for web because n Can promptly validate user input n Can update the web page without postback to server n Allows page to react to user actions other than pushing a “submit” button – more interactivity
What is Java. Script? n Interpreted, object-oriented programming language with dynamic typing n n n Introduced by Netscape with Netscape 2. 0 in 1995 Standardized as ECMAScript by ECMA (European Computer Manufacturers Association) Not related to Java other than the name n Tightly integrated with browser n Can handle many types of events generated by the normal interaction between user and browser n Can modify the internal objects based on which the browser renders the web page
<head> <title>Java. Script Hello world!</title> </head> <body> <script> document. write("Hello world!"); </script> </body>
Adding Java. Script to a page n Using the <script> </script> tag n Text between tags is Java. Script program n Can specify external file using src attribute n Executed as the document is loading n Value of an attribute such as onclick n This type of code is called event handler n Executed when event happens n Can define event handlers for almost any HTML element in page
Some events Java. Script can handle Handler Triggered when Comments Return false to cancel default action onclick Mouse click on element onchange The control’s state changes onfocus The control gets focus onsubmit The form is submitted onmouseover Mouse moves over el. onmouseout Mouse moves off el. onmousedown Mouse button pressed onmouseup Mouse button released onkeydown Key pressed down onkeypress Key pressed and released Used form elements and <body> Return false to cancel onkeyup Key released Used form elements and <body> onload Document load complete Used for <body> and <img> Specific to forms
Document Object Model n Describes how the document object from Java. Script can be traversed and modified n n n Represented as tree structure Can add new elements to the page Can change attributes of existing elements n DOM has levels 0 -3 and many sub-standards n The DOM interface used in other contexts with other languages (C++, Java, python, etc. )
The document as a tree <html> <head> <title>A Document</title> </head> <body> <h 1>A web page</h 1> <p>A <i>simple</i> paragraph</p> </body> </html> document <html> <head> <body> <title> <h 1> “A document” “A web page” <p> “A ” <i> “simple” “ paragraph”
Overview n Web documents n Server-side programming n Client-side programming n Web services
What are web services? n A form of remote procedure call: your program (the client) asks another computer (the server) to run a procedure for you n Parameters sent over the network from client to server n Results sent over network from server to client n Why would you ever want to do a remote procedure call? n Data needed for answer not (easily) accessible to your computer n You want to re-use existing procedures that run in a different environment than your program n Your computer lacks the resources (i. e. processor capacity, memory, network connection speed) to compute the result n There are many other forms of RPC older than web services n CORBA, DCOM, Sun. RPC, RMI
Internals of an RPC framework n Code for marshalling/unmarshalling – encoding and decoding parameters/results n A. k. a. serializing objects n Description of the available procedures (methods) n Using an interface description language (IDL) n Framework that turns these descriptions into “stubs” n On the client the stub makes it look to your program like the stub is executing the procedure locally n On the server the stub invokes the procedure n The client and server stub interact over the network
Specific to web services n They run over http n Procedure call is in an http request n Result is in an http response n They use XML to n Encode responses n Encode requests (sometimes) n Describe the procedures (incl. arguments and results) n Client and server often use different languages n Client may be Java. Script code in browser – AJAX n Client and server are often in different organizations
6afd0bdc16ca8828ce17da19870502c2.ppt