internet & world wide web : how to program · 2013. 4. 10. · 8 contents 2.10 tables 86 2.11...

13
PIFTH EDITION Paul Deitel Deitel & Associates, Inc. Harvey Deitel Deitel & Associates, Inc. Abbey Deitel Deitel & Associates, Inc. International Edition contributions by Soumen Mukherjee Amp Kumar Bhattacharjee Boston Columbus Indianpolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Deitel

Upload: others

Post on 17-Mar-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

PIFTH EDITION

Paul Deitel

Deitel & Associates, Inc.

Harvey Deitel

Deitel &Associates, Inc.

Abbey Deitel

Deitel &Associates, Inc.

InternationalEdition contributions by

Soumen Mukherjee Amp Kumar Bhattacharjee

Boston Columbus Indianpolis New York San Francisco Upper Saddle River

Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto

Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo

Deitel

Page 2: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

Preface

Before You Begin

1 Introduction to Computers and the In*

1.1 Introduction

1.2 The Internet in Industry and Research

1.3 HTML5, CSS3, JavaScript, Canvas and jQuery1.4 Demos

1.5 Evolution ofthe Internet and World Wide Web

1.6 Web Basics

1.7 Multitier Application Architecture

1.8 Client-Side Scripting versus Server-Side Scripting1.9 World Wide Web Consortium (W3C)1.10 Web 2.0: Going Social

1.11 Data Hierarchy1.12 Operating Systems

1.12.1 Desktop and Notebook Operating Systems1.12.2 Mobile Operating Systems

1.13 Types ofProgramming Languages1.14 Object Technology1.15 Keeping Up-to-Date with Information Technologies

2 Introduction to HTML5: Part I

2.1 Introduction

2.2 Editing HTML52.3 First HTML5 Example2.4 W3C HTML5 Validation Service

2.5 Headings2.6 Linking2.7 Images

2.7.1 alt Attribute

2.7.2 Void Elements

2.7.3 Using Images as Hyperlinks2.8 Special Characters and Horizontal Rules

2.9 Lists

Page 3: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

8 Contents

2.10 Tables 86

2.11 Forms 90

2.12 Internal Linking 97

2.13 meta Elements 99

2.14 Web Resources 101

3 Introduction to HTML5: Part 2 108

3.1 Introduction 109

3.2 New HTML5 Form input Types 109

3.2.1 input Type color 112

3.2.2 i nput Type date 114

3.2.3 i nput Type datetime 114

3.2.4 input Type datetime-local 114

3.2.5 input Type email 115

3.2.6 input Type month 116

3.2.7 input Type number 116

3.2.8 i nput Type range 117

3.2.9 i nput Type search 117

3.2.10 i nput Type tel 118

3.2.11 input Type time 118

3.2.12 input Type url 119

3.2.13 input Type week 119

3.3 input and datalist Elements and autocomplete Attribute 119

3.3.1 input Element autocomplete Attribute 119

3.3.2 datalist Element 122

3.4 Page-Structure Elements 122

3.4.1 header Element 128

3.4.2 nav Element 128

3.4.3 fi gure Element and fi gcapti on Element 128

3.4.4 article Element 128

3.4.5 summary Element and details Element 128

3.4.6 section Element 128

3.4.7 aside Element 128

3.4.8 meter Element 129

3.4.9 footer Element 130

3.4.10 Text-Level Semantics: mark Element and wbr Element 130

4 Introduction to Cascading Style Sheets

(CSS): Part I 137

4.1 Introduction 138

4.2 Inline Styles 138

4.3 Embedded Style Sheets 140

4.4 Conflicting Styles 143

4.5 Linking External Style Sheets 146

Page 4: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

Contents 9

4.6 Positioning Elements: Absolute Positioning, z-index 148

4.7 Positioning Elements: Relative Positioning, span 150

4.8 Backgrounds 152

4.9 Element Dimensions 154

4.10 Box Model and Text Flow 155

4.11 Media Types and Media Queries 15 9

4.12 Drop-Down Menus 162

4.13 (Optional) User Style Sheets 164

4.14 Web Resources 168

5 Introduction to Cascading Style Sheets

(CSS): Part 2 174

5.1 Introduction 175

5.2 Text Shadows 175

5.3 Rounded Corners 176

5.4 Color 177

5.5 Box Shadows 178

5.6 Linear Gradients; Introducing Vendor Prefixes 180

5.7 Radial Gradients 183

5.8 (Optional: WebKit Only) Text Stroke 185

5.9 Multiple Background Images 185

5.10 (Optional: WebKit Only) Reflections 187

5.11 Image Borders 188

5.12 Animation; Selectors 191

5.13 Transitions and Transformations 194

5.13.1 transition and transform Properties 194

5.13.2 Skew 196

5.13.3 Transitioning Between Images 197

5.14 Downloading Web Fonts and the ©font-face Rule 198

5.15 Flexible Box Layout Module and : nth-chi 1 d Selectors 200

5.16 Multicolumn Layout 203

5.17 Media Queries 205

5.18 Web Resources 209

6 JavaScript: Introduction to Scripting 217

6.1 Introduction 218

6.2 Your First Script: Displaying a Line ofText with JavaScript in a Web Page 218

6.3 Modifying Your First Script 221

6.4 Obtaining User Input with prompt Dialogs 224

6.4.1 Dynamic Welcome Page 224

6.4.2 Adding Integers 228

6.5 Memory Concepts 231

6.6 Arithmetic 232

6.7 Decision Making: Equality and Relational Operators 234

6.8 Web Resources 239

Page 5: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

10 Contents

7 JavaScript: Control Statements 1 246

7.1 Introduction 247

7.2 Algorithms 2477.3 Pseudocode 2477.4 Control Statements 247

7.5 i f Selection Statement 250

7.6 if...else Selection Statement 251

7.7 whi 1 e Repetition Statement 255

7.8 Formulating Algorithms: Counter-Controlled Repetition 257

7.9 Formulating Algorithms: Sentinel-Controlled Repetition 260

7.10 Formulating Algorithms: Nested Control Statements 266

7.11 Assignment Operators 270

7.12 Increment and Decrement Operators 271

7.13 Web Resources 274

8 JavaScript: Control Statements II 283

8.1 Introduction 284

8.2 Essentials ofCounter-Controlled Repetition 284

8.3 for Repetition Statement 2858.4 Examples Using the for Statement 288

8.5 swi tch Multiple-Selection Statement 2938.6 do...while Repetition Statement 296

8.7 break and continue Statements 298

8.8 Logical Operators 300

8.9 Web Resources 303

9 JavaScript: Functions 310

9.1 Introduction 3119.2 Program Modules in JavaScript 311

9.3 Function Definitions 3129.3.1 Programmer-Defined Function square 3139.3.2 Programmer-Defined Function maxi mum 315

9.4 Notes on Programmer-Defined Functions 3179.5 Random Number Generation 318

9.5.1 Scaling and Shifting Random Numbers 318

9.5.2 Displaying Random Images 3199.5.3 Rolling Dice Repeatedly and Displaying Statistics 323

9.6 Example: Game ofChance; Introducing the HTML5audio and video Elements 328

9.7 Scope Rules 3389.8 JavaScript Global Functions 3409.9 Recursion 3419.10 Recursion vs. Iteration 345

Page 6: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

Contents 11

10 JavaScript; Arrays 356

10.1 Introduction 357

10.2 Arrays 357

10.3 Declaring and Allocating Arrays 359

10.4 Examples Using Arrays 359

10.4.1 Creating, Initializing and Growing Arrays 359

10.4.2 Initializing Arrays with Initializer Lists 363

10.4.3 Summing the Elements ofan Array with for and for...in 364

10.4.4 Using the Elements of an Array as Counters 366

10.5 Random Image Generator Using Arrays 369

10.6 References and Reference Parameters 371

10.7 Passing Arrays to Functions 372

10.8 Sorting Arrays with Array Method sort 375

10.9 Searching Arrays with Array Method i ndexOf 376

10.10 Multidimensional Arrays 379

I 1 JavaScript: Objects 392

11.1 Introduction 393

11.2 Math Object 393

11.3 String Object 395

11.3.1 Fundamentals ofCharacters and Strings 395

11.3.2 Methods ofthe Stri ng Object 395

11.3-3 Character-Processing Methods 397

11.3.4 Searching Methods 398

11.3.5 Splitting Strings and Obtaining Substrings 401

11.4 Date Object 403

11.5 Boolean and Number Objects 408

11.6 document Object 409

11.7 Favorite Twitter Searches: HTML5 Web Storage 410

11.8 Using JSON to Represent Objects 417

12 Document Object Model (DOM):Objects and Collections 427

12.1 Introduction 428

12.2 Modeling a Document: DOM Nodes and Trees 428

12.3 Traversing and Modifying a DOM Tree 431

12.4 DOM Collections 441

12.5 Dynamic Styles 443

12.6 Using a Timer and Dynamic Styles to Create Animated Effects 445

13 JavaScript Event Handling: A Deeper Look 454

13.1 Introduction 455

Page 7: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

12 Contents

13.2 Reviewing the load Event 455

13.3 Event mousemove and the event Object 457

13.4 Rollovers with mouseover and mouseout 461

13.5 Form Processing with focus and blur 465

13.6 More Form Processing with submit and reset 468

13.7 Event Bubbling 470

13.8 More Events 472

13.9 Web Resource 472

14 HTML5: Introduction to canvas 476

14.1 Introduction 477

14.2 canvas Coordinate System 477

14.3 Rectangles 478

14.4 Using Paths to Draw Lines 480

14.5 Drawing Arcs and Circles 482

14.6 Shadows 484

14.7 Quadratic Curves 486

14.8 Bezier Curves 488

14.9 Linear Gradients 489

14.10 Radial Gradients 491

14.11 Images 493

14.12 Image Manipulation: Processing the Individual Pixels of a canvas 495

14.13 Patterns 499

14.14 Transformations 500

14.14.1 scale and translate Methods: Drawing Ellipses 500

14.14.2 rotate Method: Creating an Animation 502

14.14.3 transform Method: Drawing Skewed Rectangles 504

14.15 Text 50614.16 Resizing the canvas to Fill the Browser Window 508

14.17 Alpha Transparency 509

14.18 Compositing 511

14.19 Cannon Game 514

14.19.1 HTML5 Document 51614.19.2 Instance Variables and Constants 516

14.19.3 Function setupGame 518

14.19.4 Functions startTimer and stopTimer 519

14.19.5 Function resetElements 519

14.19.6 Function newGame 520

14.19.7 Function updatePositions: Manual Frame-by-FrameAnimation and Simple Collision Detection 521

14.19.8 Function fi reCannonball 524

14.19.9 Function alignCannon 52514.19. lOFunction draw 52614.19.11 Function showGameOverDialog 528

14.20 save and restore Methods 528

Page 8: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

Contents 13

14.21 A Note on SVG 530

14.22 A Note on canvas35D 531

15 XML 543

15.1 Introduction 544

15.2 XML Basics 544

15.3 Structuring Data 547

15.4 XML Namespaces 553

15.5 Document Type Definitions (DTDs) 555

15.6 W3C XML Schema Documents 558

15.7 XML Vocabularies 566

15.7.1 MathML 566

15.7.2 Other Markup Languages 569

15.8 Extensible Stylesheet Language and XSL Transformations 570

15.9 Document Object Model (DOM) 579

15.10 Web Resources 597

16 Ajax-Enabled Rich Internet Applicationswith XML and JSON 603

16.1 Introduction 604

16.1.1 Traditional Web Applications vs. Ajax Applications 605

16.1.2 Traditional Web Applications 605

16.1.3 Ajax Web Applications 606

16.2 Rich Internet Applications (RIAs) with Ajax 606

16.3 History ofAjax 609

16.4 "Raw" Ajax Example Using the XMLHttpRequest Object 609

16.4.1 Asynchronous Requests 610

16.4.2 Exception Handling 613

16.4.3 Callback Functions 614

16.4.4 XMLHttpRequest Object Event, Properties and Methods 614

16.5 Using XML and the DOM 615

16.6 Creating a Full-Scale Ajax-Enabled Application 619

16.6.1 Using JSON 619

16.6.2 Rich Functionality 620

16.6.3 Interacting with a Web Service on the Server 629

16.6.4 Parsing JSON Data 629

16.6.5 Creating HTML5 Elements and Setting Event Handlers on the Fly 630

16.6.6 Implementing Type-Ahead 630

16.6.7 Implementing a Form with Asynchronous Validation 631

1 7 Web Servers (Apache and IIS) 637

17.1 Introduction 638

17.2 HTTP Transactions 638

Page 9: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

14 Contents

17.3 Multitier Application Architecture 642

17.4 Client-Side Scripting versus Server-Side Scripting 643

17.5 Accessing Web Servers 643

17.6 Apache, MySQL and PHP Installation 643

17.6.1 XAMPP Installation 644

17.6.2 Running XAMPP 644

17.6.3 Testing Your Setup 645

17.6.4 Running the Examples Using Apache HTTP Server 645

17.7 Microsoft IIS Express and WebMatrix 646

17.7.1 Installing and Running IIS Express 646

17.7.2 Installing and Running WebMatrix 646

17.7.3 Running the Client-Side Examples Using IIS Express 646

17.7.4 Running the PHP Examples Using IIS Express 647

18 Database: SQL, MySQL, LINQ and Java DB 649

18.1 Introduction 650

18.2 Relational Databases 650

18.3 Relational Database Overview: A books Database 652

18.4 SQL 655

18.4.1 Basic SELECT Query 656

18.4.2 WHERE Clause 656

18.4.3 ORDER BY Clause 658

18.4.4 Merging Data from Multiple Tables: INNER JOIN 660

18.4.5 INSERT Statement 661

18.4.6 UPDATE Statement 663

18.4.7 DELETE Statement 663

18.5 MySQL 664

18.5.1 Instructions for Setting Up a MySQL User Account 665

18.5.2 Creating Databases in MySQL 666

18.6 (Optional) Microsoft Language Integrate Query (LINQ) 666

18.6.1 Querying an Array of i nt Values Using LINQ 667

18.6.2 Querying an Array of Employee Objects Using LINQ 669

18.6.3 Querying a Generic Collection Using LINQ 674

18.7 (Optional) LINQ to SQL 676

18.8 (Optional) Querying a Database with LINQ 677

18.8.1 Creating LINQ to SQL Classes 677

18.8.2 Data Bindings Between Controls and the LINQ to SQL Classes 680

18.9 (Optional) Dynamically Binding LINQ to SQL Query Results 684

18.9.1 Creating the Display Query Results GUI 684

18.9.2 Coding the Display Query Results Application 68618.10 Java DB/Apache Derby 688

19 PHP 69619.1 Introduction 697

19.2 Simple PHP Program 698

Page 10: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

Contents 15

19.3 Converting Between Data Types19.4 Arithmetic Operators19.5 Initializing and Manipulating Arrays19.6 String Comparisons19.7 String Processing with Regular Expressions

19.7.1 Searching for Expressions19.7.2 Representing Patterns

19.7.3 Finding Matches

19.7.4 Character Classes

19.7.5 Finding Multiple Instances of a Pattern

19.8 Form Processing and Business Logic19.8.1 Superglobal Arrays19.8.2 Using PHP to Process HTML5 Forms

19.9 Reading from a Database

19.10 Using Cookies

19.11 Dynamic Content

19.12 Web Resources

20 Web App Development with ASP.NET in C# 740

20.1 Introduction 741

20.2 Web Basics 742

20.3 Multitier Application Architecture 743

20.4 Your First ASP.NET Application 745

20.4.1 Building the WebTi me Application 747

20.4.2 Examining WebTi me. aspx's Code-Behind File 756

20.5 Standard Web Controls: Designing a Form 756

20.6 Validation Controls 761

20.7 Session Tracking 767

20.7.1 Cookies 768

20.7.2 Session Tracking with HttpSessionState 769

20.7.3 Opti ons. aspx: Selecting a Programming Language 772

20.7.4 Recommendati ons. aspx: Displaying Recommendations Based

on Session Values 775

20.8 Case Study: Database-Driven ASP.NET Guestbook 777

20.8.1 Building a Web Form that Displays Data from a Database 779

20.8.2 Modifying the Code-Behind File for the Guestbook Application 782

20.9 Case Study Introduction: ASP.NET AJAX 784

20.10 Case Study Introduction: Password-Protected Books Database Application 784

21 Web App Development with ASP.NET in C#:

A Deeper Look 790

21.1 Introduction 791

21.2 Case Study: Password-Protected Books Database Application 791

21.2.1 Examining the ASP.NET Web Site Template 792

21.2.2 Test-Driving the Completed Application 794

699

702

706

709

710

712

712

713

713

714

714

714

715

719

723

726

734

Page 11: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

16 Contents

21.2.3 Configuring the Website 79621.2.4 Modifying the Default.aspx and About, aspx Pages 799

21.2.5 Creating a Content Page That Only Authenticated Users Can Access 800

21.2.6 Linking from the Default, aspx Page to the Books, aspx Page 801

21.2.7 Modifying the Master Page (Site.master) 802

21.2.8 Customizing the Password-Protected Books .aspx Page 804

21.3 ASP.NET Ajax 809

21.3.1 Traditional Web Applications 809

21.3.2 Ajax Web Applications 810

21.3.3 Testing an ASP.NET Ajax Application 811

21.3.4 The ASP.NET Ajax Control Toolkit 812

21.3.5 Using Controls from the Ajax Control Toolkit 813

22 Web Services in C# 821

22.1 Introduction 822

22.2 WCF Services Basics 823

22.3 Simple Object Access Protocol (SOAP) 823

22.4 Representational State Transfer (REST) 824

22.5 JavaScript Object Notation QSON) 824

22.6 Publishing and Consuming SOAP-Based WCF Web Services 825

22.6.1 Creating a WCF Web Service 825

22.6.2 Code for the WeicomeSOAPXMLService 825

22.6.3 Building a SOAP WCF Web Service 826

22.6.4 Deploying the Wei comeSOAPXMLServi ce 828

22.6.5 Creating a Client to Consume the Wei comeSOAPXMLServi ce 829

22.6.6 Consuming the Wei comeSOAPXMLServi ce 831

22.7 Publishing and Consuming REST-Based XML Web Services 833

22.7.1 HTTP get and post Requests 833

22.7.2 Creating a REST-BasedXMLWCF Web Service 833

22.7.3 Consuming a REST-BasedXMLWCF Web Service 836

22.8 Publishing and Consuming REST-Based JSON Web Services 837

22.8.1 Creating a REST-Based JSON WCF Web Service 837

22.8.2 Consuming a REST-Based JSON WCF Web Service 839

22.9 Blackjack Web Service: Using Session Tracking in a SOAP-Based

WCF Web Service 841

22.9.1 Creating a Blackjack Web Service 841

22.9.2 Consuming the Blackjack Web Service 846

22.10 Airline Reservation Web Service: Database Access and Invoking a

Service from ASP.NET 85522.11 Equation Generator: Returning User-Defined Types 859

22.11.1 Creating the REST-Based XML EquationGenerator Web Service 862

22.11.2 Consuming the REST-Based XML EquationGeneratorWeb Service 863

22.11.3 Creating the REST-Based JSON WCF EquationGeneratorWeb Service 867

Page 12: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

Contents 17

22.11.4 Consuming the REST-Based JSON WCF EquationCenerator

Web Service 867

22.12 Web Resources 871

23 Web App Development with ASP.NET in

Visual Basic 879

23.1 Introduction 880

23.2 Web Basics 881

23.3 Multitier Application Architecture 882

23.4 Your First ASP.NET Application 884

23.4.1 Building the WebTi me Application 886

23.4.2 Examining WebTi me. aspx's Code-Behind File 895

23.5 Standard Web Controls: Designing a Form 896

23.6 Validation Controls 901

23.7 Session Tracking 907

23.7.1 Cookies 908

23.7-2 Session Tracking with HttpSessionState 909

23.7.3 Opti ons. aspx: Selecting a Programming Language 911

23.7.4 Recommendati ons. aspx: Displaying Recommendations Based

on Session Values 915

23.8 Case Study: Database-Driven ASP.NET Guestbook 917

23.8.1 Building a Web Form that Displays Data from a Database 919

23.8.2 Modifying the Code-Behind File for the Guestbook Application 923

23.9 Online Case Study: ASP.NET AJAX 924

23.10 Online Case Study: Password-Protected Books Database Application 924

A HTML Special Characters 930

B HTML Colors 931

C JavaScript Operator Precedence Chart 934

D ASCII Character Set 936

Index 937

Chapters 24-29 and Appendices E-F are PDF documents posted online at the book's

Companion Website (located at www.pearsoninternationaleditions.com/deitel/).

24 Web App Development with ASP.NET in VB:

A Deeper Look

Page 13: Internet & world wide web : how to program · 2013. 4. 10. · 8 Contents 2.10 Tables 86 2.11 Forms 90 2.12 InternalLinking 97 2.13 metaElements 99 2.14 WebResources 101 3 Introduction

18 Contents

25 Web Services in Visual Basic

26 JavaServer Faces Web Apps: Part I

27 JavaServer Faces Web Apps: Part 2

28 Web Services in Java

29 HTML5 WebSockets and Web Workers

E Number Systems

F Unicode®