web programming ch. 1

Upload: jabont-chamikorn

Post on 02-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Web Programming Ch. 1

    1/117

    Internet & World Wide WebHow to Program, 5/e

    Copyright Pearson, Inc. 2013. All Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    2/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    3/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    4/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    5/117

    The Internet and web programming technologiesyoull learn in this book are designed to beportable , allowing you to design web pages andapplications that run across an enormous rangeof Internet-enabled devices.Client-side programming technologies are usedto build web pages and applications that are runon the client (i.e., in the browser on the usersdevice).Server-side programming the applications thatrespond to requests from client-side webbrowsers, such as searching the Internet,checking your bank-account balance, ordering abook from Amazon, bidding on an eBay auctionand ordering concert tickets.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    6/117

    Read the Preface and the Before You Beginsection to learn about the books coverageand how to set up your computer to run thehundreds of code examples.The code is available atwww.deitel.com/books/iw3htp5 andwww.pearsonhighered.com/deitel .

    Use the source code to run every programand script as you study it.Try each example in multiple browsers .

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    7/117

    If youre interested in smartphones and tabletcomputers, run the examples in yourbrowsers on iPhones, iPads, Androidsmartphones and tablets, and others.The technologies covered in this book andbrowser support for them are evolvingrapidly. Not every feature of every page we build will render properly in every browser .

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    8/117

    Moo res Law Every year or two, the capacities of computers haveapproximately doubled inexpensively.This remarkable trend often is called Moores Law .Moores Law and related observations apply especially tothe amount of memory that computers have for programs,the amount of secondary storage (such as disk storage)they have to hold programs and data over longer periodsof time, and their processor speeds the speeds at whichcomputers execute their programs (i.e., do their work).Similar growth has occurred in the communications field,in which costs have plummeted as enormous demand forcommunications bandwidth (i.e., information-carryingcapacity) has attracted intense competition.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    9/117

    Figures 1.1 1.4 provide a few examples of how computers and the Internet are beingused in industry and research.Figure 1.1 lists two examples of howcomputers and the Internet are being used toimprove health care.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    10/117

  • 7/27/2019 Web Programming Ch. 1

    11/117

    Figure 1.2 provides a sample of some of theexciting ways in which computers and theInternet are being used for social good.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    12/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    13/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    14/117

    Figure 1.3 gives some examples of howcomputers and the Internet provide theinfrastructure to communicate, navigate,collaborate and more.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    15/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    16/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    17/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    18/117

    Figure 1.4 lists a few of the exciting ways inwhich computers and the Internet are used inentertainment.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    19/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    20/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    21/117

    HTML5HTML (HyperText Markup Language) is a specialtype of computer language called a markup language designed to specify the content andstructure of web pages (also called documents) in a

    portable manner.HTML5, now under development, is the emergingversion of HTML.HTML enables you to create content that will renderappropriately across the extraordinary range of

    devices connected to the Internet includingsmartphones, tablet computers, notebookcomputers, desktop computers, special-purposedevices such as large-screen displays at conc ertarenas and sports stadiums, and more.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    22/117

    A stricter version of HTML called XHTML (Extensible HyperText Markup Language) ,which is based on XML (eXtensible MarkupLanguage), is still used frequently today.Many of the server-side technologies wecover later in the book produce web pages asXHTML documents, by default, but the trendis clearly to HTML5.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    23/117

    Cascading Style Sheets (CSS)Although HTML5 provides some capabilities for controlling adocuments presentation, its better not to mix presentation with content .Cascading Style Sheets (CSS) are used to specify thepresentation , or styling, of elements on a web page (e.g.,fonts, spacing, sizes, colors, positioning).CSS was designed to style portable web pages independently of their content and structure.By separating page styling from page content and structure,you can easily change the look and feel of the pages on anentire website, or a portion of a website, simply by swapping

    out one style sheet for another.CSS3 is the current version of CSS under development.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    24/117

    JavaScript JavaScript helps you build dynamic web pages (i.e., pages thatcan be modified on the fly in response to events , such asuser input, time changes and more) and computerapplications.It enables you to do the client-side programming of web

    applications. JavaScript was created by Netscape.Both Netscape and Microsoft have been instrumental in thestandardization of JavaScript by ECMA International (formerlythe European Computer Manufacturers Association) asECMAScript.

    ECMAScript 5, the latest version of the standard, correspondsto the version of JavaScript we use in this book. JavaScript is a portable scripting language. Programs writtenin JavaScript can run in web browsers across a wide range of devices.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    25/117

    Web Browsers and Web-Browser PortabilityEnsuring a consistent look and feel on client-side browsers is one of the great challengesof developing web-based applications.Currently, a standard does not exist to whichsoftware vendors must adhere when creatingweb browsers.

    Although browsers share a common set of features, each browser might render pagesdifferently.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    26/117

    Browsers are available in many versions andon many different platforms (MicrosoftWindows, Apple Macintosh, Linux, UNIX, etc.).Vendors add features to each new version

    that sometimes result in cross-platformincompatibility issues.Its difficult to develop web pages that rendercorrectly on all versions of each browser.

    All of the code examples in the book weretested in the five most popular desktopbrowsers and the two most popular mobilebrowsers (Fig. 1.5).

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    27/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    28/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    29/117

    Support for HTML5, CSS3 and JavaScript features varies bybrowser.The HTML5 Test website ( http://html5test.com/ ) scoreseach browser based on its support for the latest features of these evolving standards.

    Figure 1.5 lists the five desktop browsers we use in reverseorder of their HTML5 Test scores from most compliant toleast compliant at the time of this writing.You can also check sites such as http://caniuse.com/ for alist of features covered by each browser.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    30/117

    jQuery jQuery ( jQuery.org ) is currently the mostpopular of hundreds of JavaScript libraries . www.activoinc.com/blog/2008/11/03/jquery-emerges-

    as-most-popular-javascript-library-for-web-

    development/. jQuery simplifies JavaScript programming bymaking it easier to manipulate a web pageselements and interact with servers in a portablemanner across various web browsers.

    It provides a library of custom graphical userinterface (GUI) controls (beyond the basic GUIcontrols provided by HTML5) that can be used toenhance the look and feel of your web pages.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    31/117

    Validating Your HTML5, CSS3 and JavaScriptCode

    You must use proper HTML5, CSS3 and JavaScript syntax to ensure that browsersprocess your documents properly.Figure 1.6 lists the validators we used tovalidate the code in this book. Wherepossible, we eliminated validation errors.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    32/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    33/117

    Browse the web pages in Fig. 1.7 to get asense of some of the things youll be able tocreate using the technologies youll learn inthis book, including HTML5, CSS3, JavaScript,canvas and jQuery.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    34/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    35/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    36/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    37/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    38/117

    The Internet a global network of computers was madepossible by the convergence of computing and communications technologies .In the late 1960s, ARPA (the Advanced Research ProjectsAgency) rolled out blueprints for networking the maincomputer systems of about a dozen ARPA-funded universitiesand research institutions.They were to be connected with communications linesoperating at a then-stunning 56 Kbps (i.e., 56,000 bits persecond) this at a time when most people (of the few whocould) were connecting over telephone lines to computers at

    a rate of 110 bits per second.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    39/117

    A bit (short for binary digit) is the smallest dataitem in a computer; it can assume the value 0 or1.ARPA proceeded to implement the ARPANET,which eventually evolved into todays Internet .

    Rather than enabling researchers to share eachothers computers, it rapidly became clear thatcommunicating quickly and easily via electronicmail was the key early benefit of the ARPANET.This is true even today on the Internet, whichfacilitates communications of all kinds amongthe worlds Internet users.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    40/117

    Packet SwitchingOne of the primary goals for ARPANET was to allowmultiple users to send and receive informationsimultaneously over the same communications paths(e.g., phone lines).

    The network operated with a technique called packetswitching , in which digital data was sent in smallbundles called packets .The packets contained address , error-control andsequencing information.The address information allowed packets to berouted to their destinations.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    41/117

    The sequencing information helped in reassemblingthe packets which, because of complex routingmechanisms, could actually arrive out of order intotheir original order for presentation to the recipient.Packets from different senders were intermixed onthe same lines to efficiently use the availablebandwidth.The network was designed to operate withoutcentralized control.If a portion of the network failed, the remainingworking portions would still route packets fromsenders to receivers over alternative paths forreliability.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    42/117

    TCP/IPThe protocol (i.e., set of rules) for communicating over theARPANET became known as TCPthe TransmissionControl Protocol .TCP ensured that messages were properly routed fromsender to receiver and that they arrived intact.As the Internet evolved, organizations worldwide wereimplementing their own networks for bothintraorganization (i.e., within the organization) andinterorganization (i.e., between organizations)communications.One challenge was to get these different networks tocommunicate.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    43/117

    ARPA accomplished this with the development of IPthe Internet Protocol , truly creating a network of networks, thecurrent architecture of the Internet.The combined set of protocols is now commonly calledTCP/IP .Each computer on the Internet has a unique IP address .The current IP standard, Internet Protocol version 4 (IPv4),has been in use since 1984 and will soon run out of possible addresses.IPv6 is just starting to be deployed. It features enhancedsecurity and a new addressing scheme, hugely expandingthe number of IP addresses available so that we will notrun out of IP addresses in the forseeable future.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    44/117

    Explosive GrowthInitially, Internet use was limited touniversities and research institutions; thenthe military began using it intensively.

    Eventually, the government decided to allowaccess to the Internet for commercialpurposes.Bandwidth (i.e., the information-carrying

    capacity) on the Internets is increasingrapidly as costs dramatically decline.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    45/117

    World Wide Web, HTML, HTTPThe World Wide Web allows computer users to execute web-based applicationsand to locate and view multimedia-based documents on almost any subject overthe Internet.In 1989, Tim Berners-Lee of CERN (the European Organization for NuclearResearch) began to develop a technology for sharing information via hyperlinkedtext documents.Berners-Lee called his invention the HyperText Markup Language (HTML).

    He also wrote communication protocols to form the backbone of his newinformation system, which he called the World Wide Web.In particular, he wrote the Hypertext Transfer Protocol (HTTP)a communicationsprotocol used to send information over the web.The URL (Uniform Resource Locator) specifies the address (i.e., location) of theweb page displayed in the browser window.Each web page on the Internet is associated with a unique URL.URLs usually begin with http:// .

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    46/117

    HTTPSURLs of websites that handle private information,such as credit card numbers, often begin withhttps:// , the abbreviation for Hypertext TransferProtocol Secure (HTTPS) .

    HTTPS is the standard for transferring encrypteddata on the web.It combines HTTP with the Secure Sockets Layer (SSL)and the more recent Transport Layer Security (TLS)cryptographic schemes for securing communicationsand identification information over the web.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    47/117

    Mosaic, Netscape, Emergence of W eb 2.0Web use exploded with the availability in 1993 of theMosaic browser, which featured a user-friendly graphicalinterface.Marc Andreessen, whose team at the National Center forSupercomputing Applications (NCSA) developed Mosaic,went on to found Netscape, the company that many peoplecredit with igniting the explosive Internet economy of thelate 1990s.But the dot com economic bust brought hard times in theearly 2000s.The resurgence that began in 2004 or so has been namedWeb 2.0 .

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    48/117

    In its simplest form, a web page is nothing more than anHTML (HyperText Markup Language) document (with theextension .html or .htm ) that describes to a web browserthe documents content and structure.HyperlinksHTML documents normally contain hyperlinks , which,

    when clicked, load a specified web document.Both images and text may be hyperlinked.When the user clicks a hyperlink, a web server locates therequested web page and sends it to the users webbrowser.Similarly, the user can type the address of a web page into

    the browsers address field and press Enter to view thespecified page.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    49/117

    Hyperlinks can reference other web pages, e-mailaddresses, files and more.If a hyperlinks URL is in the formmailto: emailAddress , clicking the link loadsyour default e-mail program and opens a

    message window addressed to the specified e-mail address.If a hyperlink references a file that the browser isincapable of displaying, the browser prepares todownload the file, and generally prompts the

    user for information about how the file should bestored.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    50/117

    URIs and URLsURIs (Uniform Resource Identifiers) identify resourceson the Internet.URIs that start with http:// are called URLs (Uniform Resource Locators) .

    Parts of a URLA URL contains information that directs a browser tothe resource that the user wishes to access.Web servers make such resources available to webclients.

    Popular web servers include Apaches HTTP Serverand Microsofts Internet Information Services (IIS).

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    51/117

    Lets examine the components of the URL http://www.deitel.com/books/downloads.htmlThe text http:// indicates that the HyperText Transfer Protocol(HTTP) should be used to obtain the resource.Next in the URL is the servers fully qualified hostname (forexample, www.deitel.com )the name of the web-servercomputer on which the resource resides.This computer is referred to as the host , because it houses andmaintains resources.The hostname www.deitel.com is translated into an IP (InternetProtocol) address a numerical value that uniquely identifies theserver on the Internet.An Internet Domain Name System (DNS) server maintains adatabase of hostnames and their corresponding IP addresses andperforms the translations automatically.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    52/117

    The remainder of the URL ( /books/downloads.html )specifies the resources location ( /books ) and name(downloads.html ) on the web server.The location could represent an actual directory on theweb servers file system. For security reasons, however,the location is typically a virtual directory .

    The web server translates the virtual directory into a reallocation on the server, thus hiding the resources truelocation.

    Making a Request and Receiving a ResponseFigure 1.8 shows a web browser sending a request to aweb server.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    53/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    54/117

    In Fig. 1.8, the web browser sends an HTTP requestto the server. The request (in its simplest form) isGET /books/downloads.html HTTP/1.1

    The word GET is an HTTP method indicating that theclient wishes to obtain a resource from the server.The remainder of the request provides the path nameof the resource (e.g., an HTML5 document) and theprotocols name and version number ( HTTP/1.1 ).The clients request also contains some required andoptional headers.Figure 1.9 shows the web server responding to arequest.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    55/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    56/117

    The server first sends a line of text that indicates the HTTPversion, followed by a numeric code and a phrase describing thestatus of the transaction. For example,

    HTTP/1.1 200 OKindicates success, whereas

    HTTP/1.1 404 Not foundinforms the client that the web server could not locate therequested resource.

    HTTP HeadersNext, the server sends one or more HTTP headers , which provideadditional information about the data that will be sent.In this case, the server is sending an HTML5 text document, soone HTTP header for this example would read:Content-type: text/html

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    57/117

    The information provided in this header specifies the Multipurpose Internet Mail Extensions (MIME) type of thecontent that the server is transmitting to the browser.The MIME standard specifies data formats, which programscan use to interpret data correctly.For example, the MIME type text/plain indicates that the

    sent information is text that can be displayed directly.Similarly, the MIME type image/jpeg indicates that thecontent is a JPEG image.When the browser receives this MIME type, it attempts todisplay the image.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    58/117

    The header or set of headers is followed by ablank line, which indicates to the client browserthat the server is finished sending HTTP headers.Finally, the server sends the contents of the

    requested document ( downloads.html ).The client-side browser then renders (ordisplays) the document, which may involveadditional HTTP requests to obtain associated

    CSS and images.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    59/117

    HTTP get and post RequestsThe two most common HTTP request types (also known as requestmethods ) are get and post .A get request typically gets (or retrieves) information from a server,such as an HTML document, an image or search results based on a user-submitted search term.A post request typically posts (or sends) data to a server.

    Common uses of post requests are to send form data or documents to aserver.An HTTP request often posts data to a server-side form handler thatprocesses the data.For example, when a user performs a search or participates in a web-based survey, the web server receives the information specified in theHTML form as part of the request. Get requests and post requests can

    both be used to send data to a web server, but each request type sendsthe information differently.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    60/117

    A get request appends data to the URL, e.g.,www.google.com/search?q=deitel .In this case search is the name of Googles server -side form handler, q is thename of a variable in Googles search form and deitel is the search term.The ? in the preceding URL separates the query string from the rest of the URL in arequest.A name/value pair is passed to the server with the name and the value separatedby an equals sign ( =).

    If more than one name / value pair is submitted, each pair is separated by anampersand ( &).The server uses data passed in a query string to retrieve an appropriate resourcefrom the server.The server then sends a response to the client. A get request may be initiated bysubmitting an HTML form whose method attribute is set to "get" , or by typing theURL (possibly containing a query string) directly into the browsers address bar.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    61/117

  • 7/27/2019 Web Programming Ch. 1

    62/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    63/117

    Client-Side CachingBrowsers often cache (save on disk) recently viewed web pages for quickreloading.If there are no changes between the version stored in the cache and thecurrent version on the web, this speeds up your browsing experience.An HTTP response can indicate the length of time for which the contentremains fresh.

    If this amount of time has not been reached, the browser can avoidanother request to the server. If not, the browser loads the documentfrom the cache.Similarly, theres also the not modified HTTP response, indicating thatthe file content has not changed since it was last requested (which isinformation thats send in the request).Browsers typically do not cache the servers response to a post request,

    because the next post might not return the same result.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    64/117

    Web-based applications are often multitierapplications (sometimes referred to as n -tierapplications ) that divide functionality intoseparate tiers (i.e., logical groupings of

    functionality).Figure 1.10 presents the basic structure of athree-tier web-based application .

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    65/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    66/117

    The bottom tier (also called the data tier or the information tier)maintains the applications data.This tier typically stores data in a relational database managementsystem (RDBMS).The middle tier implements business logic, controller logic andpresentation logic to control interactions between the applicationsclients and its data.The middle tier acts as an intermediary between data in the informationtier and the applications clients.The middle-tier controller logic processes client requests (such asrequests to view a product catalog) and retrieves data from thedatabase.The middle-tier presentation logic then processes data from theinformation tier and presents the content to the client.Web applications typically present data to clients as HTML documents.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    67/117

    Business logic in the middle tier enforces business rules andensures that data is reliable before the application updates adatabase or presents data to users.Business rules dictate how clients access data and howapplications process data.The top tier , or client tier, is the applications user interface,which gathers input and displays output.Users interact directly with the application through the userinterface, which is typically a web browser or a mobile device.In response to user actions (e.g., clicking a hyperlink), the clienttier interacts with the middle tier to make requests and toretrieve data from the information tier.The client tier then displays the data retrieved for the user.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    68/117

    Client-side scripting with JavaScript can be used to validate userinput, to interact with the browser, to enhance web pages, and toadd client/server communication between a browser and a webserver.Client-side scripting does have limitations, such as browserdependency; the browser or scripting host must support thescripting language and capabilities.

    Scripts are restricted from arbitrarily accessing the localhardware and file system for security reasons.Another issue is that client-side scripts can be viewed by theclient by using the browsers source -viewing capability.Sensitive information, such as passwords or other personallyidentifiable data, should not be on the client.

    All client-side data validation should be mirrored on the server.Also, placing certain operations in JavaScript on the client canopen web applications to security issues.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    69/117

    Programmers have more flexibility with server-side scripts ,which often generate custom responses for clients.For example, a client might connect to an airlines web serverand request a list of flights from Boston to San Franciscobetween April 19 and May 5. The server queries the database,dynamically generates an HTML document containing the flightlist and sends the document to the client. This technology allows

    clients to obtain the most current flight information from thedatabase by connecting to an airlines web server. Server-side scripting languages have a wider range of programmatic capabilities than their client-side equivalents.Server-side scripts also have access to server-side software thatextends server functionality Microsoft web servers use ISAPI(Internet Server Application Program Interface) extensions andApache HTTP Servers use modules .

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    70/117

    In October 1994, Tim Berners-Lee founded an organization theWorld Wide Web Consortium (W3C)devoted to developingnonproprietary, interoperable technologies for the World WideWeb.One of the W3Cs primary goals is to make the web universallyaccessible regardless of disability, language or culture.The W3C is also a standards organization.Web technologies standardized by the W3C are calledRecommendations .Current and forthcoming W3C Recommendations include theHyperText Markup Language 5 (HTML5), Cascading Style Sheets3 (CSS3) and the Extensible Markup Language (XML).

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    71/117

    In 2003 there was a noticeable shift in how peopleand businesses were using the web and developingweb-based applications.The term Web 2.0 was coined by Dale Dougherty of OReilly Media in 2003 to describe this trend. T. OReilly, What is Web 2.0: Design Patterns and Business

    Models for the Next Generation of Software. September2005.

    Generally, Web 2.0 companies use the web as aplatform to create collaborative, community-basedsites (e.g., social networking sites, blogs, wikis).

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    72/117

    Web 1 .0 versus Web 2.0Web 1.0 (the state of the web through the 1990s and early2000s) was focused on a relatively small number of companies and advertisers producing content for users toaccess (some people called it the brochure web).Web 2.0 involves the users not only do they often create

    content, but they help organize it, share it, remix it,critique it, update it, etc.One way to look at Web 1.0 is as a lecture , a small

    number of professors informing a large audience of students. In comparison, Web 2.0 is a conversation , witheveryone having the opportunity to speak and share views.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    73/117

    Architecture of ParticipationWeb 2.0 embraces an architecture of participation a design thatencourages user interaction and community contributions.The architecture of participation has influenced softwaredevelopment as well.Opensource software is available for anyone to use and modifywith few or no restrictions (well say more about open source inSection 1.12).Using collective intelligence the concept that a large diversegroup of people will create smart ideas communitiescollaborate to develop software that many people believe isbetter and more robust than proprietary software.Rich Internet Applications (RIAs) are being developed using

    technologies (such as Ajax) that have the look and feel of desktop software, enhancing a users overall experience.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    74/117

    Search Engines and Social MediaThe way we find the information on these sites isalso changing people are tagging (i.e., labeling)web content by subject or keyword in a way thathelps anyone locate information more effectively. Semantic WebIn the future, computers will learn to understandthe meaning of the data on the web thebeginnings of the Semantic Web are already

    appearing.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    75/117

    GoogleIn 1996, Stanford computer science Ph.D. candidatesLarry Page and Sergey Brin began collaborating on anew search engine.In 1997, they chose the name Google a play on themathematical term googol , a quantity represented bythe number one followed by 100 zeros (or 10 100 )a staggeringly large number.Googles ability to return extremely accurate searchresults quickly helped it become the most widelyused search engine and one of the most popular

    websites in the world.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    76/117

    Web Services and MashupsWe include in this book a substantialtreatment of web services and introduce theapplications-development methodology of

    mashups , in which you can rapidly developpowerful and intriguing applications bycombining (often free) complementary webservices and other forms of information feeds(Fig. 1.11).

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    77/117

  • 7/27/2019 Web Programming Ch. 1

    78/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    79/117

    Web services, inexpensive computers, abundanthigh-speed Internet access, open sourcesoftware and many other elements have inspirednew, exciting, lightweight business models that

    people can launch with only a small investment.Some types of websites with rich and robustfunctionality that might have required hundredsof thousands or even millions of dollars to buildin the 1990s can now be built for nominal sums.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    80/117

    AjaxAjax is one of the premier Web 2.0 softwaretechnologies (Fig. 1.12).Ajax helps Internet-based applications

    perform like desktop applications a difficulttask, given that such applications suffertransmission delays as data is shuttled backand forth between your computer and serverson the Internet.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    81/117

    Social ApplicationsFigure 1.13 discusses a few of the socialapplications that are making an impact.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    82/117

  • 7/27/2019 Web Programming Ch. 1

    83/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    84/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    85/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    86/117

    Data items processed by computers form a datahierarchy that becomes larger and more complexin structure as we progress from bits tocharacters to fields, and so on.Figure 1.14 illustrates a portion of the data

    hierarchy.Figure 1.15 summarizes the data hierarchyslevels.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    87/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    88/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    89/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    90/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    91/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    92/117

    Operating systems are software systems that make usingcomputers more convenient for users, application developersand system administrators.Operating systems provide services that allow each application toexecute safely, efficiently and concurrently (i.e., in parallel) withother applications.The software that contains the core components of the operating

    system is called the kernel .Popular desktop operating systems include Linux, Windows 7and Mac OS X.Popular mobile operating systems used in smartphones andtablets include Googles Android, Apples iOS (for iPhone, iPadand iPod Touch devices), BlackBerry OS and Windows Phone 7.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    93/117

    In this section we discuss two of the popular desktop operatingsystems the proprietary Windows operating system and theopen source Linux operating system.

    Windows A Proprietary Op erating SystemIn the mid-1980s, Microsoft developed the Windows operatingsystem , consisting of a graphical user interface built on top of

    DOSan enormously popular personal-computer operatingsystem of the time that users interacted with by typing commands.Windows borrowed from many concepts (such as icons, menusand windows) developed by Xerox PARC and popularized by earlyApple Macintosh operating systems.Windows is a proprietary operating system its controlled byMicrosoft exclusively.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    94/117

    Linux An Open-Source Operating SystemThe Linux operating system is perhaps the greatest success of the open- source movement.Open-source software departs from the proprietary softwaredevelopment style that dominated softwares early years.With open-source development, individuals and companies contribute their efforts in developing, maintaining and evolving software inexchange for the right to use that software for their own purposes,typically at no charge.Rapid improvements to computing and communications, decreasingcosts and open-source software have made it much easier and moreeconomical to create a software-based business now than just a decadeago.A great example is Facebook, which was launched from a college dormroom and built with open-source software.

    developers.facebook.com/opensource/.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    95/117

    The Linux kernel is the core of the most popular open-source, freely distributed, full-featured operating system.Its developed by a loosely organized team of volunteersand is popular in servers, personal computers andembedded systems.Unlike that of proprietary operating systems like

    Microsofts Windows and Apples Mac OS X, Linux sourcecode (the program code) is available to the public forexamination and modification and is free to download andinstall.Linux has become extremely popular on servers and inembedded systems, such as Googles Android -basedsmartphones.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    96/117

    Two of the most popular mobile operatingsystems are Apples iOS and Googles Android. Apples proprietary iPhone operating system, iOS,is derived from Apples Mac OS X and is used inthe iPhone, iPad and iPod Touch devices.

    Android the fastest growing mobile andsmartphone operating system is based on theLinux kernel and Java.One benefit of developing Android apps is theopenness of the platform. The operating system

    is open source and free.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    97/117

    Programmers write instructions in various programminglanguages, some directly understandable by computers andothers requiring intermediate translation steps.Any computer can directly understand only its own machinelanguage , defined by its hardware design.Machine languages generally consist of numbers (ultimatelyreduced to 1s and 0s). Such languages are cumbersome for

    humans.Programming in machine language the numbers that computerscould directly understand was simply too slow and tedious formost programmers.Instead, they began using Englishlike abbreviations to representelementary operations.These abbreviations formed the basis of assembly languages . Translator programs called assemblers were developed toconvert assembly-language programs to machine language.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    98/117

    Although assembly- language code is clearer to humans, itsincomprehensible to computers until translated to machinelanguage.To speed the programming process even further, high-levellanguages were developed in which single statements could bewritten to accomplish substantial tasks.High-level languages allow you to write instructions that look

    almost like everyday English and contain commonly usedmathematical expressions.Translator programs called compilers convert high-levellanguage programs into machine language .Interpreter programs were developed to execute high-levellanguage programs directly, although more slowly than compiledprograms.Figure 1.16 introduces a number of popular programminglanguages.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    99/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    100/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    101/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    102/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    103/117

  • 7/27/2019 Web Programming Ch. 1

    104/117

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    105/117

    Objects , or more precisely the classes objects come from, are essentially reusable

    software components.Almost any noun can be reasonably represented as a software object in terms of attributes (e.g., name, color and size) and behaviors (e.g., calculating, moving andcommunicating).Software developers are discovering that using a modular, object-oriented designand implementation approach can make software-development groups muchmore productive than was possible with earlier techniques object-orientedprograms are often easier to understand, correct and modify.

    The Autom obile as an Ob jectSuppose you want to drive a car and make it go faster by pressing its accelerator pedal .Before you can drive a car, someone has to design it.A car typically begins as engineering drawings, similar to the blueprints thatdescribe the design of a house.These drawings include the design for an accelerator pedal.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    106/117

    The pedal hides from the driver the complex mechanismsthat actually make the car go faster, just as the brakepedal hides the mechanisms that slow the car, and thesteering wheel hides the mechanisms that turn the car.This enables people with little or no knowledge of howengines, braking and steering mechanisms work to drive acar easily.Before you can drive a car, it must be built from theengineering drawings that describe it.A completed car has an actual accelerator pedal to makethe car go faster, but even thats not enough the carwont accelerate on its own (hopefully!), so the driver mustpress the pedal to accelerate the car.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    107/117

    Methods and ClassesPerforming a task in a program requires a method .The method houses the program statements that actually perform itstasks.It hides these statements from its user, just as a cars accelerator pedalhides from the driver the mechanisms of making the car go faster.In object-oriented programming languages, we create a program unitcalled a class to house the set of methods that perform the classs tasks.For example, a class that represents a bank account might contain onemethod to deposit money to an account, another to withdraw moneyfrom an account and a third to inquire what the accounts currentbalance is.A class is similar in concept to a cars engineering drawings, whichhouse the design of an accelerator pedal, steering wheel, and so on.

    Copyright Pearson, Inc. 2013. AllRights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    108/117

    Instantiation Just as someone has to build a car from its engineering drawings beforeyou can actually drive a car, you must build an object from a class beforea program can perform the tasks that the classs methods define.The process of doing this is called instantiation . An object is thenreferred to as an instance of its class.

    Reuse Just as a cars engineering drawings can be reused many times to buildmany cars, you can reuse a class many times to build many objects.Reuse of existing classes when building new classes and programs savestime and effort.Reuse also helps you build more reliable and effective systems, becauseexisting classes and components often have gone through extensivetesting , debugging and performance tuning .

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    109/117

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    110/117

    Messages and Method CallsWhen you drive a car, pressing its gas pedalsends a message to the car to perform a task that is, to go faster. Similarly, you send messages to an object .

    Each message is implemented as a method call that tells a method of the object to perform itstask.For example, a program might call a particularbank- account objects deposit method toincrease the accounts balance.

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    111/117

  • 7/27/2019 Web Programming Ch. 1

    112/117

    These attributes are specified as part of theobjects class.For example, a bank-account object has abalance attribute that represents the amount of money in the account.Each bank-account object knows the balance inthe account it represents, but not the balances of the other accounts in the bank.Attributes are specified by the classs instance

    variables .

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    113/117

    EncapsulationClasses encapsulate (i.e., wrap) attributes andmethods into objects an objects attributes andmethods are intimately related.Objects may communicate with one another, butnormally theyre not allowed to know how otherobjects are implemented implementation detailsare hidden within the objects themselves.This information hiding is crucial to good

    software engineering.

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    114/117

    InheritanceA new class of objects can be created quickly andconveniently by inheritance the new classabsorbs the characteristics of an existing class,possibly customizing them and adding uniquecharacteristics of its own.In our car analogy, an object of classconvertible certainly is an object of the moregeneral class automobile, but more specifically ,the roof can be raised or lowered.

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    115/117

    Figure 1.17 lists key technical and businesspublications that will help you stay up-to-date with the latest news and trends incomputer, Internet and web technology.

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    116/117

    Copyright Pearson, Inc. 2013. All

    Rights Reserved.

  • 7/27/2019 Web Programming Ch. 1

    117/117