Paul_Deitel_Harvey_Deitel_Abbey_Deitel_InterneBookZZ.org.pdf

Full Transcript

ONLINE ACCESS Thank you for purchasing a new copy of Internet & World Wide Web: How To Program, 5th Edition. Your textbook includes twelve months of prepaid access to the book’s Companion Website. This prepaid subscription provides you with full access to the following...

ONLINE ACCESS Thank you for purchasing a new copy of Internet & World Wide Web: How To Program, 5th Edition. Your textbook includes twelve months of prepaid access to the book’s Companion Website. This prepaid subscription provides you with full access to the following student support areas: t4PVSDF$PEF t0OMJOF$IBQUFST t"QQFOEJDFT Use a coin to scratch off the coating and reveal your student access code. Do not use a knife or other sharp object as it may damage the code. To access the Internet & World Wide Web: How To Program, 5th Edition Companion Website for the first time, you will need to register online using a computer with an Internet connection and a web browser. The process takes just a couple of minutes and only needs to be completed once. 1. Go to http://www.pearsonhighered.com/deitel/ 2. Click on Companion Website. 3. Click on the Register button. 4. 0OUIFSFHJTUSBUJPOQBHF FOUFSZPVSTUVEFOUBDDFTTDPEF* found beneath the scratch-off panel. Do not type the dashes. You can use lower- or uppercase. 5. Follow the on-screen instructions. If you need help at any time during the online registration process, simply click the Need Help? icon. 6. 0ODFZPVSQFSTPOBM-PHJO/BNFBOE1BTTXPSEBSFDPOGJSNFE ZPVDBOCFHJOVTJOHUIF Internet & World Wide Web: How To Program, 5th Edition Companion Website! To log in after you have registered: :PVPOMZOFFEUPSFHJTUFSGPSUIJT$PNQBOJPO8FCTJUFPODF"GUFSUIBU ZPVDBOMPHJOBOZUJNF BUIUUQXXXQFBSTPOIJHIFSFEDPNEFJUFMCZQSPWJEJOHZPVS-PHJO/BNFBOE1BTTXPSEXIFO prompted. *Important: The access code can only be used once. This subscription is valid for twelve months upon activation and is not transferable. If this access code has already been revealed, it may no longer be valid. If this is the case, you can purchase a subscription by going to http://www.pearsonhighered.com/deitel and following the on-screen instructions. Deitel® Series Page How To Program Series (continued) Visual Basic® 2010 How to Program C++ How to Program, 8/E Visual Basic® 2008 How to Program C How to Program, 6/E Visual C#® 2010 How to Program, 4/E Java™ How to Program, 9/E Visual C#® 2008 How to Program, 3/E Java™ How to Program, Late Objects Version, 8/E Internet & World Wide Web How to Program, 5/E Visual C++® 2008 How to Program, 2/E Deitel® Developer Series Visual Basic® 2010 How to Program AJAX, Rich Internet Applications and Web Visual C#® 2010 How to Program, 3/E Development for Programmers Small Java™ How to Program, 6/E Android for Programmers: An App-Driven Small C++ How to Program, 5/E Approach C++ for Programmers C# 2010 for Programmers, 3/E Simply Series iPhone® for Programmers: An App-Driven Approach Simply C++: An App-Driven Tutorial Approach Java™ for Programmers, 2/e Simply Java™ Programming: An App-Driven JavaScript for Programmers Tutorial Approach Simply C#: An App-Driven Tutorial Approach LiveLessons Video Learning Products Simply Visual Basic® 2008, 3/E: An App-Driven www.deitel.com/books/LiveLessons/ Tutorial Approach Android App Development Fundamentals CourseSmart Web Books C++ Fundamentals Java™ Fundamentals www.deitel.com/books/CourseSmart/ C# Fundamentals C++ How to Program, 5/E, 6/E, 7/E & 8/E iPhone® App Development Fundamentals Simply C++: An App-Driven Tutorial Approach JavaScript Fundamentals Java™ How to Program, 6/E, 7/E, 8/E & 9/E Visual Basic Fundamentals Simply Visual Basic 2008: An App-Driven Tutorial Approach, 3/E (continued next column) To receive updates on Deitel publications, Resource Centers, training courses, partner offers and more, please register for the free Deitel® Buzz Online e-mail newsletter at: www.deitel.com/newsletter/subscribe.html and join the Deitel communities on Twitter® @deitel and Facebook® facebook.com/DeitelFan/ To communicate with the authors, send e-mail to: [email protected] For information on government and corporate Dive-Into® Series on-site seminars offered by Deitel & Associates, Inc. worldwide, visit: www.deitel.com/training/ or write to [email protected] For continuing updates on Prentice Hall/Deitel publications visit: www.deitel.com www.pearsonhighered.com/deitel/ Visit the Deitel Resource Centers that will help you master programming languages, software develop- ment, Android and iPhone/iPad app development, and Internet- and web-related topics: www.deitel.com/ResourceCenters.html Paul Deitel Deitel & Associates, Inc. Harvey Deitel Deitel & Associates, Inc. Abbey Deitel Deitel & Associates, Inc. Editorial Director: Marcia J. Horton Editor-in-Chief: Michael Hirsch Associate Editor: Carole Snyder Vice President, Marketing: Patrice Jones Marketing Manager: Yezan Alayan Marketing Coordinator: Kathryn Ferranti Vice President, Production: Vince O’Brien Managing Editor: Jeff Holcomb Associate Managing Editor: Robert Engelhardt Operations Specialist: Lisa McDowell Art Director: Anthony Gemmellaro Cover Design: Paul Deitel, Harvey Deitel, Abbey Deitel, Marta Samsel Cover Photo Credit: © 2008 realeoni/Flickr/Getty Images Media Editor: Daniel Sandin Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on page vi. The authors and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and pub- lisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in this book. The authors and publisher shall not be liable in any event for incidental or consequential dam- ages in connection with, or arising out of, the furnishing, performance, or use of these programs. Copyright © 2012, 2008, 2004, 2002, 2000 Pearson Education, Inc., publishing as Prentice Hall. All rights reserved. Manufactured in the United States of America. This publication is protected by Copyright, and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 501 Boylston Street, Suite 900, Boston, Massachusetts 02116. Many of the designations by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial caps or all caps. Library of Congress Cataloging-in-Publication Data Deitel, Paul J. Internet and world wide web : how to program / Paul Deitel, Harvey Deitel, Abbey Deitel. -- 5th ed. p. cm. ISBN 978-0-13-215100-9 1. Internet programming. 2. World Wide Web. I. Deitel, Harvey M., II. Deitel, Abbey. III. Title. QA76.625.D47 2012 006.7'6--dc23 2011037118 10 9 8 7 6 5 4 3 2 1 ISBN-10: 0-13-215100-6 ISBN-13: 978-0-13-215100-9 In memory of Paul Baran, designer of a survivable distributed communications network and packet switching, which are the basis for the protocols used on the Internet today. Paul, Harvey and Abbey Deitel Trademarks DEITEL, the double-thumbs-up bug and DIVE INTO are registered trademarks of Deitel & Associates, Inc. Apache is a trademark of The Apache Software Foundation. Apple, iPhone, iPad, iOS and Safari are registered trademarks of Apple, Inc. CSS, DOM, XHTML and XML are trademarks of the World Wide Web Consortium. Firefox is a registered trademark of the Mozilla Foundation. Google is a trademark of Google, Inc. JavaScript, Java and all Java-based marks are trademarks or registered trademarks of Oracle in the United States and other countries. Microsoft, Internet Explorer, Silverlight and the Windows logo are either registered trademarks or trade- marks of Microsoft Corporation in the United States and/or other countries. Opera is a trademark of Opera Software. Contents Preface xix Before You Begin xxxi 1 Introduction to Computers and the Internet 1 1.1 Introduction 2 1.2 The Internet in Industry and Research 3 1.3 HTML5, CSS3, JavaScript, Canvas and jQuery 6 1.4 Demos 9 1.5 Evolution of the Internet and World Wide Web 10 1.6 Web Basics 12 1.7 Multitier Application Architecture 16 1.8 Client-Side Scripting versus Server-Side Scripting 17 1.9 World Wide Web Consortium (W3C) 18 1.10 Web 2.0: Going Social 18 1.11 Data Hierarchy 23 1.12 Operating Systems 25 1.12.1 Desktop and Notebook Operating Systems 25 1.12.2 Mobile Operating Systems 26 1.13 Types of Programming Languages 27 1.14 Object Technology 29 1.15 Keeping Up-to-Date with Information Technologies 31 2 Introduction to HTML5: Part 1 37 2.1 Introduction 38 2.2 Editing HTML5 38 2.3 First HTML5 Example 38 2.4 W3C HTML5 Validation Service 41 2.5 Headings 41 2.6 Linking 42 2.7 Images 45 2.7.1 alt Attribute 47 2.7.2 Void Elements 47 2.7.3 Using Images as Hyperlinks 47 2.8 Special Characters and Horizontal Rules 49 2.9 Lists 51 viii Contents 2.10 Tables 54 2.11 Forms 58 2.12 Internal Linking 65 2.13 meta Elements 67 2.14 Web Resources 69 3 Introduction to HTML5: Part 2 76 3.1 Introduction 77 3.2 New HTML5 Form input Types 77 3.2.1 input Type color 80 3.2.2 input Type date 82 3.2.3 input Type datetime 82 3.2.4 input Type datetime-local 82 3.2.5 input Type email 83 3.2.6 input Type month 84 3.2.7 input Type number 84 3.2.8 input Type range 85 3.2.9 input Type search 85 3.2.10 input Type tel 86 3.2.11 input Type time 86 3.2.12 input Type url 87 3.2.13 input Type week 87 3.3 input and datalist Elements and autocomplete Attribute 87 3.3.1 input Element autocomplete Attribute 87 3.3.2 datalist Element 90 3.4 Page-Structure Elements 90 3.4.1 header Element 96 3.4.2 nav Element 96 3.4.3 figure Element and figcaption Element 96 3.4.4 article Element 96 3.4.5 summary Element and details Element 96 3.4.6 section Element 96 3.4.7 aside Element 96 3.4.8 meter Element 97 3.4.9 footer Element 98 3.4.10 Text-Level Semantics: mark Element and wbr Element 98 4 Introduction to Cascading Style Sheets™ (CSS): Part 1 105 4.1 Introduction 106 4.2 Inline Styles 106 4.3 Embedded Style Sheets 108 4.4 Conflicting Styles 111 4.5 Linking External Style Sheets 114 Contents ix 4.6 Positioning Elements: Absolute Positioning, z-index 116 4.7 Positioning Elements: Relative Positioning, span 118 4.8 Backgrounds 120 4.9 Element Dimensions 122 4.10 Box Model and Text Flow 123 4.11 Media Types and Media Queries 127 4.12 Drop-Down Menus 130 4.13 (Optional) User Style Sheets 132 4.14 Web Resources 136 5 Introduction to Cascading Style Sheets™ (CSS): Part 2 142 5.1 Introduction 143 5.2 Text Shadows 143 5.3 Rounded Corners 144 5.4 Color 145 5.5 Box Shadows 146 5.6 Linear Gradients; Introducing Vendor Prefixes 148 5.7 Radial Gradients 151 5.8 (Optional: WebKit Only) Text Stroke 153 5.9 Multiple Background Images 153 5.10 (Optional: WebKit Only) Reflections 155 5.11 Image Borders 156 5.12 Animation; Selectors 159 5.13 Transitions and Transformations 162 5.13.1 transition and transform Properties 162 5.13.2 Skew 164 5.13.3 Transitioning Between Images 165 5.14 Downloading Web Fonts and the @font-face Rule 166 5.15 Flexible Box Layout Module and :nth-child Selectors 168 5.16 Multicolumn Layout 171 5.17 Media Queries 173 5.18 Web Resources 177 6 JavaScript: Introduction to Scripting 185 6.1 Introduction 186 6.2 Your First Script: Displaying a Line of Text with JavaScript in a Web Page 186 6.3 Modifying Your First Script 189 6.4 Obtaining User Input with prompt Dialogs 192 6.4.1 Dynamic Welcome Page 192 6.4.2 Adding Integers 196 6.5 Memory Concepts 199 6.6 Arithmetic 200 6.7 Decision Making: Equality and Relational Operators 202 6.8 Web Resources 207 x Contents 7 JavaScript: Control Statements I 214 7.1 Introduction 215 7.2 Algorithms 215 7.3 Pseudocode 215 7.4 Control Statements 215 7.5 if Selection Statement 218 7.6 if…else Selection Statement 219 7.7 while Repetition Statement 223 7.8 Formulating Algorithms: Counter-Controlled Repetition 225 7.9 Formulating Algorithms: Sentinel-Controlled Repetition 228 7.10 Formulating Algorithms: Nested Control Statements 234 7.11 Assignment Operators 238 7.12 Increment and Decrement Operators 239 7.13 Web Resources 242 8 JavaScript: Control Statements II 251 8.1 Introduction 252 8.2 Essentials of Counter-Controlled Repetition 252 8.3 for Repetition Statement 253 8.4 Examples Using the for Statement 256 8.5 switch Multiple-Selection Statement 261 8.6 do…while Repetition Statement 264 8.7 break and continue Statements 266 8.8 Logical Operators 268 8.9 Web Resources 271 9 JavaScript: Functions 278 9.1 Introduction 279 9.2 Program Modules in JavaScript 279 9.3 Function Definitions 280 9.3.1 Programmer-Defined Function square 281 9.3.2 Programmer-Defined Function maximum 283 9.4 Notes on Programmer-Defined Functions 285 9.5 Random Number Generation 286 9.5.1 Scaling and Shifting Random Numbers 286 9.5.2 Displaying Random Images 287 9.5.3 Rolling Dice Repeatedly and Displaying Statistics 291 9.6 Example: Game of Chance; Introducing the HTML5 audio and video Elements 296 9.7 Scope Rules 306 9.8 JavaScript Global Functions 308 9.9 Recursion 309 9.10 Recursion vs. Iteration 313 Contents xi 10 JavaScript: Arrays 324 10.1 Introduction 325 10.2 Arrays 325 10.3 Declaring and Allocating Arrays 327 10.4 Examples Using Arrays 327 10.4.1 Creating, Initializing and Growing Arrays 327 10.4.2 Initializing Arrays with Initializer Lists 331 10.4.3 Summing the Elements of an Array with for and for…in 332 10.4.4 Using the Elements of an Array as Counters 334 10.5 Random Image Generator Using Arrays 337 10.6 References and Reference Parameters 339 10.7 Passing Arrays to Functions 340 10.8 Sorting Arrays with Array Method sort 343 10.9 Searching Arrays with Array Method indexOf 344 10.10 Multidimensional Arrays 347 11 JavaScript: Objects 360 11.1 Introduction 361 11.2 Math Object 361 11.3 String Object 363 11.3.1 Fundamentals of Characters and Strings 363 11.3.2 Methods of the String Object 363 11.3.3 Character-Processing Methods 365 11.3.4 Searching Methods 366 11.3.5 Splitting Strings and Obtaining Substrings 369 11.4 Date Object 371 11.5 Boolean and Number Objects 376 11.6 document Object 377 11.7 Favorite Twitter Searches: HTML5 Web Storage 378 11.8 Using JSON to Represent Objects 385 12 Document Object Model (DOM): Objects and Collections 395 12.1 Introduction 396 12.2 Modeling a Document: DOM Nodes and Trees 396 12.3 Traversing and Modifying a DOM Tree 399 12.4 DOM Collections 409 12.5 Dynamic Styles 411 12.6 Using a Timer and Dynamic Styles to Create Animated Effects 413 13 JavaScript Event Handling: A Deeper Look 422 13.1 Introduction 423 xii Contents 13.2 Reviewing the load Event 423 13.3 Event mousemove and the event Object 425 13.4 Rollovers with mouseover and mouseout 429 13.5 Form Processing with focus and blur 433 13.6 More Form Processing with submit and reset 436 13.7 Event Bubbling 438 13.8 More Events 440 13.9 Web Resource 440 14 HTML5: Introduction to canvas 444 14.1 Introduction 445 14.2 canvas Coordinate System 445 14.3 Rectangles 446 14.4 Using Paths to Draw Lines 448 14.5 Drawing Arcs and Circles 450 14.6 Shadows 452 14.7 Quadratic Curves 454 14.8 Bezier Curves 456 14.9 Linear Gradients 457 14.10 Radial Gradients 459 14.11 Images 461 14.12 Image Manipulation: Processing the Individual Pixels of a canvas 463 14.13 Patterns 467 14.14 Transformations 468 14.14.1 scale and translate Methods: Drawing Ellipses 468 14.14.2 rotate Method: Creating an Animation 470 14.14.3 transform Method: Drawing Skewed Rectangles 472 14.15 Text 474 14.16 Resizing the canvas to Fill the Browser Window 476 14.17 Alpha Transparency 477 14.18 Compositing 479 14.19 Cannon Game 482 14.19.1 HTML5 Document 484 14.19.2 Instance Variables and Constants 484 14.19.3 Function setupGame 486 14.19.4 Functions startTimer and stopTimer 487 14.19.5 Function resetElements 487 14.19.6 Function newGame 488 14.19.7 Function updatePositions: Manual Frame-by-Frame Animation and Simple Collision Detection 489 14.19.8 Function fireCannonball 492 14.19.9 Function alignCannon 493 14.19.10 Function draw 494 14.19.11 Function showGameOverDialog 496 14.20 save and restore Methods 496 Contents xiii 14.21 A Note on SVG 498 14.22 A Note on canvas 3D 499 15 XML 511 15.1 Introduction 512 15.2 XML Basics 512 15.3 Structuring Data 515 15.4 XML Namespaces 521 15.5 Document Type Definitions (DTDs) 523 15.6 W3C XML Schema Documents 526 15.7 XML Vocabularies 534 15.7.1 MathML™ 534 15.7.2 Other Markup Languages 537 15.8 Extensible Stylesheet Language and XSL Transformations 538 15.9 Document Object Model (DOM) 547 15.10 Web Resources 565 16 Ajax-Enabled Rich Internet Applications with XML and JSON 571 16.1 Introduction 572 16.1.1 Traditional Web Applications vs. Ajax Applications 573 16.1.2 Traditional Web Applications 573 16.1.3 Ajax Web Applications 574 16.2 Rich Internet Applications (RIAs) with Ajax 574 16.3 History of Ajax 577 16.4 “Raw” Ajax Example Using the XMLHttpRequest Object 577 16.4.1 Asynchronous Requests 578 16.4.2 Exception Handling 581 16.4.3 Callback Functions 582 16.4.4 XMLHttpRequest Object Event, Properties and Methods 582 16.5 Using XML and the DOM 583 16.6 Creating a Full-Scale Ajax-Enabled Application 587 16.6.1 Using JSON 587 16.6.2 Rich Functionality 588 16.6.3 Interacting with a Web Service on the Server 597 16.6.4 Parsing JSON Data 597 16.6.5 Creating HTML5 Elements and Setting Event Handlers on the Fly 598 16.6.6 Implementing Type-Ahead 598 16.6.7 Implementing a Form with Asynchronous Validation 599 17 Web Servers (Apache and IIS) 605 17.1 Introduction 606 17.2 HTTP Transactions 606 xiv Contents 17.3 Multitier Application Architecture 610 17.4 Client-Side Scripting versus Server-Side Scripting 611 17.5 Accessing Web Servers 611 17.6 Apache, MySQL and PHP Installation 611 17.6.1 XAMPP Installation 612 17.6.2 Running XAMPP 612 17.6.3 Testing Your Setup 613 17.6.4 Running the Examples Using Apache HTTP Server 613 17.7 Microsoft IIS Express and WebMatrix 614 17.7.1 Installing and Running IIS Express 614 17.7.2 Installing and Running WebMatrix 614 17.7.3 Running the Client-Side Examples Using IIS Express 614 17.7.4 Running the PHP Examples Using IIS Express 615 18 Database: SQL, MySQL, LINQ and Java DB 617 18.1 Introduction 618 18.2 Relational Databases 618 18.3 Relational Database Overview: A books Database 620 18.4 SQL 623 18.4.1 Basic SELECT Query 624 18.4.2 WHERE Clause 624 18.4.3 ORDER BY Clause 626 18.4.4 Merging Data from Multiple Tables: INNER JOIN 628 18.4.5 INSERT Statement 629 18.4.6 UPDATE Statement 631 18.4.7 DELETE Statement 631 18.5 MySQL 632 18.5.1 Instructions for Setting Up a MySQL User Account 633 18.5.2 Creating Databases in MySQL 634 18.6 (Optional) Microsoft Language Integrate Query (LINQ) 634 18.6.1 Querying an Array of int Values Using LINQ 635 18.6.2 Querying an Array of Employee Objects Using LINQ 637 18.6.3 Querying a Generic Collection Using LINQ 642 18.7 (Optional) LINQ to SQL 644 18.8 (Optional) Querying a Database with LINQ 645 18.8.1 Creating LINQ to SQL Classes 645 18.8.2 Data Bindings Between Controls and the LINQ to SQL Classes 648 18.9 (Optional) Dynamically Binding LINQ to SQL Query Results 652 18.9.1 Creating the Display Query Results GUI 652 18.9.2 Coding the Display Query Results Application 654 18.10 Java DB/Apache Derby 656 19 PHP 664 19.1 Introduction 665 19.2 Simple PHP Program 666 Contents xv 19.3 Converting Between Data Types 667 19.4 Arithmetic Operators 670 19.5 Initializing and Manipulating Arrays 674 19.6 String Comparisons 677 19.7 String Processing with Regular Expressions 678 19.7.1 Searching for Expressions 680 19.7.2 Representing Patterns 680 19.7.3 Finding Matches 681 19.7.4 Character Classes 681 19.7.5 Finding Multiple Instances of a Pattern 682 19.8 Form Processing and Business Logic 682 19.8.1 Superglobal Arrays 682 19.8.2 Using PHP to Process HTML5 Forms 683 19.9 Reading from a Database 687 19.10 Using Cookies 691 19.11 Dynamic Content 694 19.12 Web Resources 702 20 Web App Development with ASP.NET in C# 708 20.1 Introduction 709 20.2 Web Basics 710 20.3 Multitier Application Architecture 711 20.4 Your First ASP.NET Application 713 20.4.1 Building the WebTime Application 715 20.4.2 Examining WebTime.aspx’s Code-Behind File 724 20.5 Standard Web Controls: Designing a Form 724 20.6 Validation Controls 729 20.7 Session Tracking 735 20.7.1 Cookies 736 20.7.2 Session Tracking with HttpSessionState 737 20.7.3 Options.aspx: Selecting a Programming Language 740 20.7.4 Recommendations.aspx: Displaying Recommendations Based on Session Values 743 20.8 Case Study: Database-Driven ASP.NET Guestbook 745 20.8.1 Building a Web Form that Displays Data from a Database 747 20.8.2 Modifying the Code-Behind File for the Guestbook Application 750 20.9 Case Study Introduction: ASP.NET AJAX 752 20.10 Case Study Introduction: Password-Protected Books Database Application 752 21 Web App Development with ASP.NET in C#: A Deeper Look 758 21.1 Introduction 759 21.2 Case Study: Password-Protected Books Database Application 759 21.2.1 Examining the ASP.NET Web Site Template 760 21.2.2 Test-Driving the Completed Application 762 xvi Contents 21.2.3 Configuring the Website 764 21.2.4 Modifying the Default.aspx and About.aspx Pages 767 21.2.5 Creating a Content Page That Only Authenticated Users Can Access 768 21.2.6 Linking from the Default.aspx Page to the Books.aspx Page 769 21.2.7 Modifying the Master Page (Site.master) 770 21.2.8 Customizing the Password-Protected Books.aspx Page 772 21.3 ASP.NET Ajax 777 21.3.1 Traditional Web Applications 777 21.3.2 Ajax Web Applications 778 21.3.3 Testing an ASP.NET Ajax Application 779 21.3.4 The ASP.NET Ajax Control Toolkit 780 21.3.5 Using Controls from the Ajax Control Toolkit 781 22 Web Services in C# 789 22.1 Introduction 790 22.2 WCF Services Basics 791 22.3 Simple Object Access Protocol (SOAP) 791 22.4 Representational State Transfer (REST) 792 22.5 JavaScript Object Notation (JSON) 792 22.6 Publishing and Consuming SOAP-Based WCF Web Services 793 22.6.1 Creating a WCF Web Service 793 22.6.2 Code for the WelcomeSOAPXMLService 793 22.6.3 Building a SOAP WCF Web Service 794 22.6.4 Deploying the WelcomeSOAPXMLService 796 22.6.5 Creating a Client to Consume the WelcomeSOAPXMLService 797 22.6.6 Consuming the WelcomeSOAPXMLService 799 22.7 Publishing and Consuming REST-Based XML Web Services 801 22.7.1 HTTP get and post Requests 801 22.7.2 Creating a REST-Based XML WCF Web Service 801 22.7.3 Consuming a REST-Based XML WCF Web Service 804 22.8 Publishing and Consuming REST-Based JSON Web Services 805 22.8.1 Creating a REST-Based JSON WCF Web Service 805 22.8.2 Consuming a REST-Based JSON WCF Web Service 807 22.9 Blackjack Web Service: Using Session Tracking in a SOAP-Based WCF Web Service 809 22.9.1 Creating a Blackjack Web Service 809 22.9.2 Consuming the Blackjack Web Service 814 22.10 Airline Reservation Web Service: Database Access and Invoking a Service from ASP.NET 823 22.11 Equation Generator: Returning User-Defined Types 827 22.11.1 Creating the REST-Based XML EquationGenerator Web Service 830 22.11.2 Consuming the REST-Based XML EquationGenerator Web Service 831 22.11.3 Creating the REST-Based JSON WCF EquationGenerator Web Service 835 Contents xvii 22.11.4 Consuming the REST-Based JSON WCF EquationGenerator Web Service 835 22.12 Web Resources 839 23 Web App Development with ASP.NET in Visual Basic 847 23.1 Introduction 848 23.2 Web Basics 849 23.3 Multitier Application Architecture 850 23.4 Your First ASP.NET Application 852 23.4.1 Building the WebTime Application 854 23.4.2 Examining WebTime.aspx’s Code-Behind File 863 23.5 Standard Web Controls: Designing a Form 864 23.6 Validation Controls 869 23.7 Session Tracking 875 23.7.1 Cookies 876 23.7.2 Session Tracking with HttpSessionState 877 23.7.3 Options.aspx: Selecting a Programming Language 879 23.7.4 Recommendations.aspx: Displaying Recommendations Based on Session Values 883 23.8 Case Study: Database-Driven ASP.NET Guestbook 885 23.8.1 Building a Web Form that Displays Data from a Database 887 23.8.2 Modifying the Code-Behind File for the Guestbook Application 891 23.9 Online Case Study: ASP.NET AJAX 892 23.10 Online Case Study: Password-Protected Books Database Application 892 A HTML Special Characters 898 B HTML Colors 899 C JavaScript Operator Precedence Chart 902 D ASCII Character Set 904 Index 905 Chapters 24–29 and Appendices E–F are PDF documents posted online at the book’s Companion Website (located at www.pearsonhighered.com/deitel/). 24 Web App Development with ASP.NET in VB: A Deeper Look xviii Contents 25 Web Services in Visual Basic 26 JavaServer™ Faces Web Apps: Part 1 27 JavaServer™ Faces Web Apps: Part 2 28 Web Services in Java 29 HTML5 WebSockets and Web Workers E Number Systems F Unicode® Preface Science and technology and the various forms of art, all unite humanity in a single and interconnected system. —Zhores Aleksandrovich Medvede Welcome to Internet and web programming with Internet & World Wide Web How to Pro- gram, Fifth Edition! This book presents leading-edge computing technologies for students, instructors and software developers. The world of computing—and Internet and web programming in particular—has changed dramatically since the last edition. This new edition focuses on HTML5 and the related technologies in its ecosystem, diving into the exciting new features of HTML5, CSS3, the latest edition of JavaScript (ECMAScript 5) and HTML5 canvas. We focus on popular key technologies that will help you build Internet- and web-based applications that interact with other applications and with databases. These form the basis of the kinds of enterprise-level, networked applications that are popular in industry today. Internet & World Wide Web How to Program, 5/e is appropriate for both introductory and intermediate-level client-side and server-side programming courses. The book is also suitable for professionals who want to update their skills with the latest Internet and web programming technologies. At the heart of the book is the Deitel signature “live-code approach”—concepts are presented in the context of complete working HTML5 documents, CSS3 stylesheets, JavaScript scripts, XML documents, programs and database files, rather than in code snip- pets. Each complete code example is accompanied by live sample executions. The source code is available at www.deitel.com/books/iw3htp5/ and at the book’s Companion Website www.pearsonhighered.com/deitel/. As you read the book, if you have questions, send an e-mail to [email protected]; we’ll respond promptly. For updates on this book, visit www.deitel.com/books/iw3htp5/, join our communities on Facebook (www.facebook.com/deitelfan) and Twitter (@deitel), and subscribe to the Deitel ® Buzz Online newsletter (www.deitel.com/news- letter/subscribe.html). New and Updated Features Here are the updates we’ve made for Internet & World Wide Web How to Program, 5/e: New Chapter 1. The new Chapter 1 engages students with intriguing facts and figures to get them excited about studying Internet and web applications devel- opment. The chapter includes a table of some of the research made possible by xx Preface computers and the Internet, current technology trends and hardware discussion, the data hierarchy, a new section on social networking, a table of popular web ser- vices, a table of business and technology publications and websites that will help you stay up to date with the latest technology news and trends, and updated ex- ercises. New HTML5 features. Chapter 3 introduces the latest features of HTML5 including the new HTML5 form input types and page structure elements (Fig. 1). The new HTML5 features are not universally implemented in all of the web browsers. This is changing as the browser vendors release new versions. We discuss many additional HTML5 features throughout the book. New HTML5 features Form Input Types color date datetime datetime-local email month number range search tel time url week input element datalist element autocomplete attribute Page Structure Elements header nav figure figcaption article summary section aside meter footer text-level semantics (marking potential line breaks) Fig. 1 | New HTML5 form input types and page structure elements New CSS3 features. Chapter 5 introduces the latest features of CSS3 (Fig. 2). The new CSS3 features are not universally implemented in all of the web browsers. This is changing as the browser vendors release new versions. New CSS3 features text shadows rounded corners color box shadows linear gradients radial gradients multiple background images image borders animations transitions transformations @font-face rule Flexible Box Layout Module :nth-child selectors multicolumn layouts media queries Non-standard features text stroke reflection Fig. 2 | New CSS3 features. New and Updated Features xxi Updated treatment of JavaScript. We’ve strengthened the JavaScript coverage in Chapters 6–16. JavaScript has become the de facto standard client-side scripting language for web-based applications due to its highly portable nature. Our treat- ment, which is appropriate for novices, serves two purposes—it introduces client- side scripting (Chapters 6–16), which makes web pages more dynamic and inter- active, and it provides the programming foundation for the server-side scripting in PHP presented in Chapter 19. JavaScript looks similar to basic core language features in C, C++, C# and Java. Once you learn JavaScript, you’ve got a foothold on learning these other popular programming languages. New HTML5 canvas. Chapter 14 replaces the Flash and Silverlight chapters from the previous edition with the new HTML5 canvas element for 2D graphics (Fig. 3). canvas is built into the browser, eliminating the need for plug-ins like Flash and Silverlight, and helping you improve performance and convenience, and reduce costs. At the end of the chapter, you’ll use canvas to build a fun, an- imated Cannon Game with audio effects, which we built in Flash in previous edi- tions of this book. HTML5 canvas features rectangles lines arcs and circles shadows quadratic curves Bezier curves linear gradients radial gradients image manipulation images patterns transformations alpha transparency compositing Fig. 3 | HTML5 canvas features. New and updated multimedia exercises. Chapter 14 includes several new and up- dated multimedia exercises (Fig. 4). New and updated multimedia exercises Cannon Game Enhance- Random Interimage Digital Clock ments Transition Background Audio Animation Scrolling Image Marquee Analog Clock Scrolling Marquee Sign Automatic Jigsaw Puzzle Maze Generator and Dynamic Audio and Generator Walker Graphical Kaleidoscope Horse Race Shuffleboard One-Armed Bandit Fireworks Designer Floor Planner Game of Pool 15 Puzzle Reaction Time Tester Crossword Puzzle Coloring Black-and-White Vacuuming Robot Rotating Images Photographs and Images Eyesight Tester Fig. 4 | New and updated multimedia exercises. xxii Preface Tested on seven browsers. For the last edition of this book, we tested all the code on two desktop browsers—Internet Explorer and Firefox. For this new edition, we tested all of the code in the most current versions of seven popular browsers—five for the desktop (Chrome, Internet Explorer, Firefox, Opera and Safari) and two for mobile devices (iPhone/iPad and Android). HTML5 and CSS3 are evolving and the final standards have not been approved yet. The browser vendors are selec- tively implementing features that are likely to be standardized. Some vendors have higher levels of feature compliance than others. With each new version of the browsers, the trend has been to significantly increase the amount of functionality that’s been implemented. The HTML5 test site (html5test.com) measures how well each browser supports the pending standards and specifications. You can view test scores and see which features are supported by each browser. You can also check sites such as http://caniuse.com/ for a list of features covered by each browser. Not every document in this book will render properly in each browser. Instead of choosing only capabilities that exist universally, we demonstrate exciting new features in whatever browser handles the new functionality best. As you read this book, run each example in multiple web browsers so you can view and interact with it as it was originally intended. And remember, things are changing quickly, so a browser that did not support a feature when we wrote the book could support it when you read the book. Validated HTML5, CSS3 and JavaScript code. All of the HTML5, CSS3 and JavaScript code in the book was validated using validator.w3.org/ for HTML5, jigsaw.w3.org/css-validator for CSS3 and javascriptlint.com for JavaScript. Not every script fully validates but most do. Although all of the code works properly, you may receive warnings (or possibly errors) when validating code with some of the new features. Smartphone and tablet apps. You’re probably familiar with the explosion of apps available for the iPhone/iPad and Android platforms. There’s almost a million apps between the two. Previously, writing apps for these platforms required de- tailed knowledge of each, and in the case of iPhone/iPad, was strictly controlled by Apple; Android is more open. With the techniques you’ll learn in this book, you’ll be able to write apps that are portable between a great variety of desktop and mobile platforms, including iPhone/iPad and Android. You’ll even be able to sell those apps on your own terms (or through certain app stores as well). This is an exciting possibility! It’s one of the true virtues of developing with HTML5, CSS3 and JavaScript in general, and HTML5 canvas in particular. Running an HTML5 app on your smartphone or tablet is as simple as opening it in your com- pliant web browser. You may still encounter some portability issues. New HTML5 web storage capabilities. In Chapter 11, we use HTML5’s new web storage capabilities to create a web application that stores a user’s favorite Twitter searches on the computer for easy access at a later time. Web storage re- places the controversial cookie technology, offering lots more storage space. Chapter 11 also briefly introduces JSON, a means for creating JavaScript ob- jects—typically for transferring data over the Internet between client-side and server-side programs. New and Updated Features xxiii Enhanced Craps game featuring HTML5 audio and video elements. The Craps game in Chapter 9 now includes an HTML5 audio element that plays a dice-roll- ing sound each time the user rolls the dice. Also, we link to a page with an embed- ded HTML5 video element that plays a video explaining the rules of the game. jQuery Ajax case study. The previous edition of this book included a calendar ap- plication that used the Dojo libraries—which were popular at the time—to create the user interface, communicate with the server asynchronously, handle events and manipulate the DOM. Since then, jQuery has become the most popular JavaScript library. For this edition, we’ve updated the calendar application (Chapter 16) using jQuery and placed it online as a jQuery Ajax case study. New HTML5 WebSockets and Web Workers capabilities. We’ve added an online treatment of two new technologies—WebSockets, which provides a simple model for networking, and Web Workers which provides multithreading on a web page. Ajax-enabled web applications. We’ve updated the chapter on building Ajax-en- abled web applications, with applications that demonstrate partial-page updates and type-ahead capabilities—each of these are key capabilities of Rich Internet Applications. HTML DOM and XML DOM. We’ve enhanced the treatments of HTML DOM manipulation, JavaScript events and XML DOM manipulation with JavaScript. LINQ. Since the last edition of the book, Microsoft introduced LINQ (Lan- guage-Integrated Query) to replace SQL for database access. Chapter 18 provides an introduction to LINQ basics and an introduction to LINQ to SQL (the tech- nology that replaces SQL). Updated PHP coverage. Chapter 19 has been updated to the latest version of PHP. If you start this book as a novice and study the JavaScript in Chapters 6– 13, you’ll have the programming experience needed to understand server-side programming in PHP. [Our treatment of server-side programming in ASP.NET requires knowledge of C# or Visual Basic, and in JSF requires knowledge of Java.] ASP.NET, ASP.NET Ajax and web services. This updated three-chapter se- quence is now provided for each of Microsoft’s two key applications development languages—C# and Visual Basic. The C# chapters and the first VB chapter are in the print book and the remaining Visual Basic chapters are available online at the book’s Companion Website (see the inside front cover). JavaServer Faces (JSF), JSF Ajax and web services. This updated three-chapter sequence, available online, emphasizes building Ajax-enabled JSF applications. Web services. We now provide chapters on building both SOAP-based web ser- vices and REST-based web services with ASP.NET in Visual Basic, ASP.NET in C# and JSF in Java. Client/Server applications. Several client-side case studies now enable students to interact with preimplemented web services that we host at test.deitel.com. xxiv Preface New and updated case studies. The book includes rich case studies using various technologies—Deitel Cover Viewer (JavaScript/DOM), Address Book (Ajax), Cannon Game (HTML5 Canvas), Mailing List (PHP/MySQL), Guest Book and Password-Protected Books Database (ASP.NET), Address Book (JavaServer Faces) and Blackjack (JAX-WS web services). New Pedagogic Features Making a Difference exercises in Chapter 1. We encourage you to use computers and the Internet to research and solve significant social problems. These exercises are meant to increase awareness and discussion of important issues the world is fac- ing. We hope you’ll approach them with your own values, politics and beliefs. Check out the many Making a Difference resources we provide, including our new Making a Difference Resource Center at www.deitel.com/MakingADifference for additional ideas you may want to investigate further. Page numbers for key terms in chapter summaries. For key terms that appear in the Chapters 1–19 summaries, we include the page number of the key term’s de- fining occurrence in the text. Dependency Chart The chart in Fig. 5 shows the book’s modular organization and the dependencies among the chapters to help instructors plan their syllabi. Internet & World Wide Web How to Pro- gram, 5/e, is appropriate for a variety of introductory and intermediate -level programming courses, most notably client-side programming and server-side programming. Chapters 1–23 are in the printed book; Chapters 24–29 and some appendices are online. We recommend that you study all of a given chapter’s dependencies before studying that chapter, though other orders are certainly possible. Some of the dependencies apply only to sections of chapters, so we advise instructors to browse the material before designing a course of study. This book is intended for courses that teach pure client-side web programming, courses that teach pure server-side web programming, and courses that mix and match some of each. Readers interested in studying server-side technologies should understand how to build web pages using HTML5 and CSS3, and object-based programming in JavaScript. Chapters 15 and 16 can be taught as part of a client-side unit, at the beginning of a server-side unit or split between the two. HTML5 Accessibility Online Appendix According to the W3C Web Accessibility Initiative, your web pages and applications should be accessible so that “people with disabilities can perceive, understand, navigate, and interact with the web, and that they can contribute to the web.”1 In an online appendix, we enumer- ate accessibility issues you should consider when designing web pages and web-based appli- cations. We also provide resources that show you how to use HTML5, CSS3, JavaScript and various design techniques to create accessible web pages and applications. As appropriate, we tie the information in this appendix back to the appropriate chapters and sections so that you can see how the applications may be enhanced to improve web accessibility. 1. http://www.w3.org/WAI/intro/accessibility.php. HTML5 Accessibility Online Appendix xxv Introduction Introduction to Server-Side 1 Intro to Computers and the Internet Development 17 Web Servers (Apache and IIS) Intro to HTML5 and CSS3 18 Database: SQL, MySQL, 2 Introduction to HTML5: Part 1 LINQ to SQL and Java DB 3 Introduction to HTML5: Part 2 19 PHP1 4 Introduction to Cascading Style Sheets™ (CSS): Part 1 Server-Side Development with ASP.NET and C#2 20 Web App Development 5 Introduction to Cascading Style Sheets™ with ASP.NET in C# (CSS): Part 2 21 Web App Development Programming Fundamentals with ASP.NET in C#: A Deeper Look in JavaScript 6 JavaScript: Introduction to Scripting 22 Web Services in C# 7 JavaScript: Control Statements I Server-Side Development with ASP.NET and VB3 8 JavaScript: Control Statements II 23 Web App Development with ASP.NET in Visual Basic 9 JavaScript Functions 24 Web App Development 10 JavaScript: Arrays with ASP.NET in VB: A Deeper Look 11 JavaScript: Objects 25 Web Services in Visual Basic 12 Document Object Model (DOM): Objects Server-Side Development with and Collections JavaServer Faces and Java4 26 JavaServer™ Faces Web Apps: Part 1 13 JavaScript Event Handling: A Deeper Look 27 JavaServer™ Faces Web Apps: Part 2 14 HTML5: Introduction to Canvas 28 Web Services in Java Foundations of Ajax 15 XML WebSockets and Web Workers 29 HTML5 WebSockets and Web Workers 16 Ajax-Enabled Rich Internet Applications 1. Chapter 19 assumes only that you’re familiar with the programming fundamentals presented in Chapters 6–13. 2. The C# chapters require knowledge of C# and the Microsoft.NET class libraries. 3. The Visual Basic chapters require knowledge of Visual Basic and the Microsoft.NET class libraries. 4. The Java chapters require knowledge of Java and the Java class libraries. Fig. 5 | Internet & World Wide Web How to Program, 5/e chapter dependency chart. xxvi Preface HTML5 Geolocation Online Appendix The HTML5 Geolocation API allows you to build web applications that gather location information (i.e,. latitude and longitude coordinates) using technologies like GPS, IP addresses, WiFi connections or cellular tower connections. It’s supported by the seven desktop and mobile browsers we used to test the code throughout the book. The Geolocation API specification lists several use cases,2 including: finding points of interest in the user's area annotating content with location information showing the user's position on a map providing route navigation alerting the user when points of interest are nearby providing up-to-date local information tagging locations in status updates on social networking sites For example, you could create a location-based mobile web app that uses GPS location in- formation from a smartphone to track a runner’s route on a map, calculate the distance traveled and the average speed. Similarly, you could create an app that returns a list of nearby businesses. In this online appendix, we build a mobile location-based app. Teaching Approach Internet & World Wide Web How to Program, 5/e, contains hundreds of complete working examples across a wide variety of markup, styling, scripting and programming languages. We stress clarity and concentrate on building well-engineered software. Syntax Shading. For readability, we syntax shade the code, similar to the way most inte- grated-development environments and code editors syntax color the code. Our syntax- shading conventions are: comments appear like this keywords appear like this constants and literal values appear like this all other code appears in black Code Highlighting. We place gray rectangles around key code segments. Using Fonts for Emphasis. We place the key terms and the index’s page reference for each defining occurrence in bold text for easy reference. We emphasize on-screen components in the bold Helvetica font (for example, the File menu) and program text in the Lucida font (for example, int count = 5). Web Access. All of the source-code examples can be downloaded from: www.deitel.com/books/iw3htp5 www.pearsonhighered.com/deitel Objectives. The opening quotes are followed by a list of chapter objectives. 2. http://www.w3.org/TR/geolocation-API/#usecases_section. Teaching Approach xxvii Illustrations/Figures. Abundant tables, line drawings, documents, scripts, programs and program outputs are included. Programming Tips. We include programming tips to help you focus on important aspects of software development. These tips and practices represent the best we’ve gleaned from a combined seven decades of programming and teaching experience. Good Programming Practices The Good Programming Practices call attention to techniques that will help you pro- duce programs that are clearer, more understandable and more maintainable. Common Programming Errors Pointing out these Common Programming Errors reduces the likelihood that you’ll make them. Error-Prevention Tips These tips contain suggestions for exposing and removing bugs from your programs; many of the tips describe aspects of programming that prevent bugs from getting into programs. Performance Tips These tips highlight opportunities for making your scripts and programs run faster or min- imizing the amount of memory that they occupy. Portability Tips The Portability Tips help you write code that will run on a variety of platforms. Software Engineering Observations The Software Engineering Observations highlight architectural and design issues that affect the construction of software systems, especially large-scale systems. Summary Bullets. We present a section-by-section bullet-list summary of the chapter for rapid review of key points. For ease of reference, we include the page number of each key term’s defining occurrence in the text. Self-Review Exercises and Answers. Extensive self-review exercises and answers are includ- ed for self study. Exercises. The chapter exercises include: simple recall of important terminology and concepts What’s wrong with this code? writing individual statements writing complete functions and scripts major projects Index. We’ve included an extensive index. Defining occurrences of key terms are high- lighted with a bold page number. xxviii Preface CourseSmart Web Books Today’s students and instructors have increasing demands on their time and money. Pear- son has responded to that need by offering digital texts and course materials online through CourseSmart. CourseSmart allows faculty to review course materials online, sav- ing time and costs. It offers students a high-quality digital version of the text for less than the cost of a print copy of the text. Students receive the same content offered in the print textbook enhanced by search, note-taking and printing tools. For more information, visit www.coursesmart.com. Instructor Resources The following supplements are available to qualified instructors only through Pearson Education’s Instructor Resource Center (www.pearsonhighered.com/irc): PowerPoint® slides containing all the code and figures in the text, plus bulleted items that summarize key points. Solutions Manual with solutions to many of the end-of-chapter exercises. Please check the Instructor Resource Center to determine which exercises have solu- tions. Please do not write to us requesting access to the Pearson Instructor’s Resource Center. Access is restricted to college instructors teaching from the book. Instructors may obtain access only through their Pearson representatives. If you’re not a registered faculty mem- ber, contact your Pearson representative or visit www.pearsonhighered.com/educator/ replocator/. Solutions are not provided for “project” exercises. Check out our Programming Proj- ects Resource Center for lots of additional exercise and project possibilities (www.deitel.com/ProgrammingProjects/). Acknowledgments We’d like to thank Barbara Deitel for long hours devoted to this project. We’re fortunate to have worked with the dedicated team of publishing professionals at Pearson. We appre- ciate the guidance, savvy and energy of Michael Hirsch, Editor-in-Chief of Computer Sci- ence. Carole Snyder recruited the book’s reviewers and managed the review process. Bob Engelhardt managed the book’s production. Reviewers We wish to acknowledge the efforts of our fourth and fifth edition reviewers. They scru- tinized the text and the programs and provided countless suggestions for improving the presentation: Timothy Boronczyk (Consultant), Roland Bouman (MySQL AB), Chris Bowen (Microsoft), Peter Brandano (KoolConnect Technologies, Inc.), Matt Chotin (Adobe), Chris Cornutt (PHPDeveloper.org), Phil Costa (Adobe), Umachitra Damo- daran (Sun Microsystems), Vadiraj Deshpande (Sun Microsystems), Justin Erenkrantz (The Apache Software Foundation), Christopher Finke (Netscape), Jesse James Garrett (Adaptive Path), Mike Harsh (Microsoft), Chris Heilmann (Mozilla), Kevin Henrikson (Zimbra.com), Tim Heuer (Microsoft), Molly E. Holtzschlag (W3C), Ralph Hooper (University of Alabama, Tuscaloosa), Chris Horton (University of Alabama), John Hrva- tin (Microsoft), Johnvey Hwang (Splunk, Inc.), Joe Kromer (New Perspective and the About the Authors xxix Pittsburgh Adobe Flash Users Group), Jennifer Kyrnin (Web Design Guide at About.com), Eric Lawrence (Microsoft), Pete LePage (Microsoft), Dr. Roy Levow (Flori- da Atlantic University), Billy B. L. Lim (Illinois State University), Shobana Mahadevan (Sun Microsystems), Patrick Mineault (Freelance Flash Programmer), Anand Narayanas- wamy (Microsoft), John Peterson (Insync and V.I.O., Inc.), Jennifer Powers (University of Albany), Ignacio Ricci (Ignacioricci.com), Jake Rutter (onerutter.com), Robin Schu- macher (MySQL AB), José Antonio González Seco (Parlamento de Andalucia), Dr. George Semeczko (Royal & SunAlliance Insurance Canada), Steven Shaffer (Penn State University), Michael Smith (W3C), Karen Tegtmeyer (Model Technologies, Inc.), Paul Vencill (MITRE), Raymond Wen (Microsoft), Eric M. Wendelin (Auto-trol Technology Corporation), Raymond F. Wisman (Indiana University), Keith Wood (Hyro, Ltd.) and Daniel Zappala (Brigham Young University). As you read the book, we’d appreciate your comments, criticisms, corrections and suggestions for improvement. Please address all correspondence to: [email protected] We’ll respond promptly. We hope you enjoy working with Internet & World Wide Web How to Program, 5/e. Paul, Harvey and Abbey Deitel About the Authors Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of MIT, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered hundreds of Java, C++, C, C#, Visual Basic and Internet programming courses to industry clients, including Cisco, IBM, Siemens, Sun Microsystems, Dell, Lu- cent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, White Sands Missile Range, Rogue Wave Software, Boeing, SunGard Higher Education, Stratus, Cambridge Technology Partners, One Wave, Hyperion Soft- ware, Adra Systems, Entergy, CableData Systems, Nortel Networks, Puma, iRobot, In- vensys and many more. He and his co-author, Dr. Harvey M. Deitel, are the world’s best- selling programming-language textbook authors. Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 50 years of experience in the computer field. Dr. Deitel earned B.S. and M.S. degrees from MIT and a Ph.D. from Boston University. He has extensive college teaching experience, including earning tenure and serving as the Chairman of the Computer Sci- ence Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of dozens of books and LiveLessons video packages and they are writing many more. The Deitels’ texts have earned interna- tional recognition, with translations published in Japanese, German, Russian, Chinese, Spanish, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish. Dr. Deitel has delivered hundreds of professional programming seminars to major corpora- tions, academic institutions, government organizations and the military. Abbey Deitel, President of Deitel & Associates, Inc., is a graduate of Carnegie Mellon University's Tepper School of Management where she received a B.S. in Industrial Man- agement. Abbey has been managing the business operations of Deitel & Associates, Inc. xxx Preface for 14 years. She has contributed to numerous Deitel & Associates publications and is the co-author of iPhone for Programmers: An App-Driven Approach and Android for Program- mers: An App-Driven Approach. Corporate Training from Deitel & Associates, Inc. Deitel & Associates, Inc., is an internationally recognized corporate training and authoring organization. The company provides instructor-led courses delivered at client sites world- wide on major programming languages and platforms, such as Java™, C++, Visual C++®, C, Visual C#®, Visual Basic®, XML®, Python®, object technology, Internet and web pro- gramming, Android™ and iPhone® app development, and a growing list of additional programming and software-development courses. The founders of Deitel & Associates, Inc., are Paul J. Deitel and Dr. Harvey M. Deitel. The company’s clients include many of the world’s largest companies, government agencies, branches of the military, and academ- ic institutions. Through its 36-year publishing partnership with Prentice Hall/Pearson, Deitel & Associates publishes leading-edge programming textbooks, professional books and LiveLessons video courses. Deitel & Associates, Inc., and the authors can be reached via e-mail at: [email protected] To learn more about the company, its publications and its Dive Into® Series Corporate Training curriculum delivered at client locations worldwide, visit: www.deitel.com/training/ subscribe to the Deitel® Buzz Online e-mail newsletter at: www.deitel.com/newsletter/subscribe.html and join the authors’ communities on Facebook (www.facebook.com/DeitelFan) and Twit- ter (@deitel). Individuals wishing to purchase Deitel books, and LiveLessons video training courses can do so through www.deitel.com. Bulk orders by corporations, the government, the military and academic institutions should be placed directly with Pearson. For more infor- mation, visit www.pearsonhighered.com About the Front Cover: Fractal Art The cover of this book features a fractal—a geometric figure that can be generated from a pattern repeated recursively. The figure is modified by applying the pattern to each seg- ment of the original figure. Although these figures were studied before the 20th century, it was the mathematician Benoit Mandelbrot, who in the 1970s introduced the term “frac- tal,” along with the specifics of how a fractal is created and the practical applications of fractals. Fractal geometry provides mathematical models for many complex forms found in nature, such as mountains, clouds and coastlines. Fractals can also be used to under- stand systems or patterns that appear in nature (e.g., ecosystems), in the human body (e.g., in the folds of the brain), or in the universe (e.g., galaxy clusters). Not all fractals resemble objects in nature. Drawing fractals has become a popular art form. We discuss recursion in Section 9.9. Before You Begin Please follow these instructions to download the book’s examples and ensure you have a current web browser before you begin using this book. Obtaining the Source Code The examples for Internet & World Wide Web How To Program, 5/e are available for down- load at www.deitel.com/books/iw3htp5/ If you’re not already registered at our website, go to www.deitel.com and click the Register link below our logo in the upper-left corner of the page. Fill in your information. There’s no charge to register, and we do not share your information with anyone. We send you only account-management e-mails unless you register separately for our free Deitel ® Buzz Online e-mail newsletter at www.deitel.com/newsletter/subscribe.html. After registering for the site, you’ll receive a confirmation e-mail with your verification code. Click the link in the confirmation e-mail to complete your registration. Configure your e-mail client to allow e-mails from deitel.com to ensure that the confirmation email is not filtered as junk mail. Next, go to www.deitel.com and sign in using the Login link below our logo in the upper-left corner of the page. Go to www.deitel.com/books/iw3htp5/. You’ll find the link to download the examples under the heading Download Code Examples and Other Pre- mium Content for Registered Users. Write down the location where you choose to save the ZIP file on your computer. Extract the example files to your hard disk using a ZIP file extractor program. If you are working in a computer lab, ask your instructor where you can save the example code. Web Browsers Used in This Book We tested all of the code in the most current versions of seven popular browsers—five for the desktop (Chrome, Internet Explorer, Firefox, Opera and Safari) and two for mobile devices (iPhone and Android). HTML5 and CSS3 are evolving and the final standards have not been approved yet. The browser vendors are selectively implementing features that are likely to become a part of the standards. Some vendors have higher levels of feature compliance than others. With each new version of the browsers, the trend has been to sig- nificantly increase the amount of functionality that’s been implemented. The HTML5 test site (html5test.com) measures how well each browser supports the pending standards and specifications. You can view test scores and see which features are supported by each browser. You can also check sites such as http://caniuse.com/ for a list of features cov- ered by each browser. Not every document in this book will render properly in each brows- er. Instead of choosing only capabilities that exist universally, we demonstrate exciting new xxxii Before You Begin features in whatever browser handles the new functionality best. As you read this book, run each example in multiple web browsers so you can view and interact with it as it was originally intended. And remember, things are changing quickly, so a browser that did not support a feature when we wrote the book could support it when you read the book. Web Browser Download Links You can download the desktop browsers from the following locations: Google Chrome: http://www.google.com/chrome Mozilla Firefox: http://www.mozilla.org/firefox/new/ Microsoft Internet Explorer (Windows only): http://www.microsoft.com/ie Apple Safari: http://www.apple.com/safari/ Opera: http://www.opera.com/ We recommend that you install all the browsers that are available for your platform. Software for the C# and Visual Basic ASP.NET Chapters The C# (Chapters 20–22) and Visual Basic (Chapters 23–25) ASP.NET and web services chapters require Visual Web Developer 2010 Express and SQL Server 2008 Express. These tools are downloadable from www.microsoft.com/express. You should follow the default installation instructions for each. Software for the JavaServer Faces and Java Web Services Chapters The software required for the JavaServer Faces and Java Web Services chapters (Chapters 26–28) is discussed at the beginning of Chapter 26. You’re now ready to begin your web programming studies with Internet & World Wide Web How to Program, 5/e. We hope you enjoy the book! If you have any questions, please feel free to email us at [email protected]. We’ll respond promptly. Introduction to Computers and the Internet 1 People are using the web to build things they have not built or written or drawn or communicated anywhere else. —Tim Berners-Lee How wonderful it is that nobody need wait a single moment before starting to improve the world. —Anne Frank Man is still the most extraordinary computer of all. —John F. Kennedy Objectives In this chapter you’ll learn: I Computer hardware, soft- ware and Internet basics. I The evolution of the Internet and the World Wide Web. I How HTML5, CSS3 and JavaScript are improving web- application development. I The data hierarchy. I The different types of programming languages. I Object-technology concepts. I And you’ll see demos of interesting and fun Internet applications you can build with the technologies you’ll learn in this book. 2 Chapter 1 Introduction to Computers and the Internet 1.1 Introduction 1.10 Web 2.0: Going Social 1.2 The Internet in Industry and Research 1.11 Data Hierarchy 1.3 HTML5, CSS3, JavaScript, Canvas 1.12 Operating Systems and jQuery 1.12.1 Desktop and Notebook Operating Systems 1.4 Demos 1.12.2 Mobile Operating Systems 1.5 Evolution of the Internet and World 1.13 Types of Programming Languages Wide Web 1.14 Object Technology 1.6 Web Basics 1.15 Keeping Up-to-Date with 1.7 Multitier Application Architecture Information Technologies 1.8 Client-Side Scripting versus Server- Side Scripting 1.9 World Wide Web Consortium (W3C) Self-Review Exercises | Answers to Self-Review Exercises | Exercises 1.1 Introduction Welcome to the exciting and rapidly evolving world of Internet and web programming! There are more than two billion Internet users worldwide—that’s approximately 30% of the Earth’s population.1 In use today are more than a billion general-purpose computers, and billions more embedded computers are used in cell phones, smartphones, tablet com- puters, home appliances, automobiles and more—and many of these devices are connect- ed to the Internet. According to a study by Cisco Internet Business Solutions Group, there were 12.5 billion Internet-enabled devices in 2010, and the number is predicted to reach 25 billion by 2015 and 50 billion by 2020.2 The Internet and web programming technol- ogies you’ll learn in this book are designed to be portable, allowing you to design web pages and applications that run across an enormous range of Internet-enabled devices. You’ll begin by learning the client-side programming technologies used to build web pages and applications that are run on the client (i.e., in the browser on the user’s device). You’ll use HyperText Markup Language 5 (HTML5) and Cascading Style Sheets 3 (CSS3)—the recent releases of HTML and CSS technologies—to add powerful, dynamic and fun features and effects to web pages and web applications, such as audio, video, ani- mation, drawing, image manipulation, designing pages for multiple screen sizes, access to web storage and more. You’ll learn JavaScript—the language of choice for implementing the client side of Internet-based applications (we discuss JavaScript in more detail in Section 1.3). Chapters 6–13 present rich coverage of JavaScript and its capabilities. You’ll also learn about jQuery—the JavaScript library that’s dramatically reshaping the world of web devel- opment. Throughout the book there’s also an emphasis on Ajax development, which helps you create better-performing, more usable applications. Later in the book, you’ll learn server-side programming—the applications that respond to requests from client-side web browsers, such as searching the Internet, checking your 1. www.internetworldstats.com/stats.htm. 2. www.cisco.com/web/about/ac79/docs/innov/IoT_IBSG_0411FINAL.pdf. 1.2 The Internet in Industry and Research 3 bank-account balance, ordering a book from Amazon, bidding on an eBay auction and ordering concert tickets. We present condensed treatments of four popular Internet/web programming languages for building the server side of Internet- and web-based client/ server applications. Chapters 19–22 and 23–28 present three popular server-side technol- ogies, including PHP, ASP.NET (in both C# and Visual Basic) and JavaServer Faces. Be sure to read both the Preface and the Before You Begin section to learn about the book’s coverage and how to set up your computer to run the hundreds of code examples. The code is available at www.deitel.com/books/iw3htp5 and www.pearsonhighered.com/ deitel. Use the source code we provide to run every program and script as you study it. Try each example in multiple browsers. If you’re interested in smartphones and tablet computers, be sure to run the examples in your browsers on iPhones, iPads, Android smartphones and tablets, and others. The technologies covered in this book and browser support for them are evolving rapidly. Not every feature of every page we build will render properly in every browser. All seven of the browsers we use are free. Moore’s Law Every year, you probably expect to pay at least a little more for most products and services. The opposite has been the case in the computer and communications fields, especially with regard to the costs of hardware supporting these technologies. For many decades, hardware costs have fallen rapidly. Every year or two, the capacities of computers have ap- proximately doubled inexpensively. This remarkable trend often is called Moore’s Law, named for the person who identified it, Gordon Moore, co-founder of Intel—the leading manufacturer of the processors in today’s computers and embedded systems. Moore’s Law and related observations apply especially to the amount of memory that computers have for programs, the amount of secondary storage (such as disk storage) they have to hold pro- grams and data over longer periods of time, and their processor speeds—the speeds at which computers execute their programs (i.e., do their work). Similar growth has occurred in the communications field, in which costs have plummeted as enormous demand for communications bandwidth (i.e., information-carrying capacity) has attracted intense competition. We know of no other fields in which technology improves so quickly and costs fall so rapidly. Such phenomenal improvement is truly fostering the Information Rev- olution. 1.2 The Internet in Industry and Research These are exciting times in the computer field. Many of the most influential and successful businesses of the last two decades are technology companies, including Apple, IBM, Hew- lett Packard, Dell, Intel, Motorola, Cisco, Microsoft, Google, Amazon, Facebook, Twit- ter, Groupon, Foursquare, Yahoo!, eBay and many more. These companies are major employers of people who study computer science, information systems or related disci- plines. At the time of this writing, Apple was the most valuable company in the world. In the past, most computer applications ran on computers that were not connected to one another, whereas today’s Internet applications can be written to communicate among computers throughout the world. Figures 1.1–1.4 provide a few examples of how computers and the Internet are being used in industry and research. Figure 1.1 lists two examples of how computers and the Internet are being used to improve health care. 4 Chapter 1 Introduction to Computers and the Internet Name Description Electronic health These might include a patient's medical history, prescriptions, immuni- records zations, lab results, allergies, insurance information and more. Making this information available to health care providers across a secure net- work improves patient care, reduces the probability of error and increases overall efficiency of the health care system. Human Genome The Human Genome Project was founded to identify and analyze the Project 20,000+ genes in human DNA. The project used computer programs to analyze complex genetic data, determine the sequences of the bil- lions of chemical base pairs that make up human DNA and store the information in databases which have been made available over the Internet to researchers in many fields. Fig. 1.1 | Computers and the Internet in health care. Figure 1.2 provides a sample of some of the exciting ways in which computers and the Internet are being used for social good. In the exercises at the end of this chapter, you’ll be asked to propose other projects that would use computers and the Internet to “make a dif- ference.” Name Description AMBER™ Alert The AMBER (America’s Missing: Broadcast Emergency Response) Alert System is used to find abducted children. Law enforcement notifies TV and radio broadcasters and state transportation officials, who then broadcast alerts on TV, radio, computerized highway signs, the Internet and wireless devices. AMBER Alert recently partnered with Facebook, whose users can “Like” AMBER Alert pages by location to receive alerts in their news feeds. World People worldwide can donate their unused computer processing power Community Grid by installing a free secure software program that allows the World Community Grid (www.worldcommunitygrid.org) to harness unused capacity. This computing power, accessed over the Internet, is used in place of expensive supercomputers to conduct scientific research projects that are making a difference, providing clean water to third- world countries, fighting cancer, growing more nutritious rice for regions fighting hunger and more. One Laptop Per One Laptop Per Child (one.laptop.org) is providing low-power, inex- Child (OLPC) pensive, Internet-enabled laptops to poor children worldwide— enabling learning and reducing the digital divide. Fig. 1.2 | Projects that use computers and the Internet for social good. We rely on computers and the Internet to communicate, navigate, collaborate and more. Figure 1.3 gives some examples of how computers and the Internet provide the infrastructure for these tasks. 1.2 The Internet in Industry and Research 5 Name Description Cloud Cloud computing allows you to use software, hardware and information computing stored in the “cloud”—i.e., accessed on remote computers via the Internet and available on demand—rather than having it stored on your personal computer. Amazon is one of the leading providers of public cloud comput- ing services. You can rent extra storage capacity using the Amazon Simple Storage Service (Amazon S3), or augment processing capabilities with Ama- zon’s EC2 (Amazon Elastic Compute Cloud). These services, allowing you to increase or decrease resources to meet your needs at any given time, are generally more cost effective than purchasing expensive hardware to ensure that you have enough storage and processing power to meet your needs at their peak levels. Business applications (such as CRM software) are often expensive, require significant hardware to run them and knowledgeable sup- port staff to ensure that they’re running properly and securely. Using cloud computing services shifts the burden of managing these applications from the business to the service provider, saving businesses money. GPS Global Positioning System (GPS) devices use a network of satellites to retrieve location-based information. Multiple satellites send time-stamped signals to the GPS device, which calculates the distance to each satellite based on the time the signal left the satellite and the time the signal arrived. This information is used to determine the exact location of the device. GPS devices can provide step-by-step directions and help you easily find nearby businesses (restaurants, gas stations, etc.) and points of interest. GP

Use Quizgecko on...
Browser
Browser