Tải bản đầy đủ (.pdf) (551 trang)

professional web 2.0 programming (2006)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (11.58 MB, 551 trang )

Professional
Web 2.0 Programming
01_087889 ffirs.qxp 10/19/06 3:55 PM Page i
01_087889 ffirs.qxp 10/19/06 3:55 PM Page ii
Professional
Web 2.0 Programming
Eric van der Vlist, Alessandro Vernet,
Erik Bruchez, Joe Fawcett, and Danny Ayers
01_087889 ffirs.qxp 10/19/06 3:55 PM Page iii
Professional Web 2.0 Programming
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN-13: 978-0-470-08788-6
ISBN-10: 0-470-08788-9
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1MA/QX/RR/QW/IN
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under
Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the
Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Cen-
ter, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for
permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indi-
anapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at />LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE
NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS


OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING
WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY
MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND
STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS
SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING
LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS
REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT.
NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HERE-
FROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A
CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT
THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR
WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE
AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAP-
PEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services or to obtain technical support, please contact our
Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317)
572-4002.
Library of Congress Cataloging-in-Publication Data is available from the publisher.
Trademarks:
Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade
dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United
States and other countries, and may not be used without written permission. All other trademarks are the
property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor
mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not
be available in electronic books.
01_087889 ffirs.qxp 10/19/06 3:55 PM Page iv
To my wife Catherine and children Deborah, David, Samuel, and Sarah for
the high tribute they have paid to this book through my lack of availability!
— E. van der V.

Dedicated to my wonderful wife, Yue. You have changed my life for the
best, and I love you more than I can say.
— A.V.
To Carol, for her patience and support during those working evenings and
weekends.
— E.B.
To my wife Gillian and my children, Persephone and Xavier, who make it
all worthwhile.
— J.F.
I dedicate my contribution to this book to our dog Basil, who missed out on
a lot of walks while I worked.
— D.A.
For Virgil Matheson
— M.D.
01_087889 ffirs.qxp 10/19/06 3:55 PM Page v
About the Authors
Eric van der Vlist is an independent consultant and trainer. His domain of expertise includes Web devel-
opment and XML technologies. He is the creator and main editor of XMLfr.org, the main site dedicated
to XML technologies in French, the author of the O’Reilly books
XML Schema and RELAX NG, and a
member or the ISO DSDL (
) working group, which focuses on XML schema lan-
guages. He is based in Paris and you can reach him by mail (
) or meet him at one of
the many conferences where he presents his projects.
Alessandro Vernet has been involved with web and XML technologies from day one. Prior to
co-founding Orbeon, he worked at Symantec Corporation as part of the VisualCafe team, working on
the next-generation RAD for web applications. He is the co-author of
The Best of Java, received the 1998
Logitech Award for his master’s thesis on Jaskell, and is one of the architects of the open source Orbeon

PresentationServer (OPS) project. His current interests lie in XML technologies and web applications.
He recently implemented an XForms engine using Ajax/JavaScript, co-authored the XML Pipeline
Language specification published by the W3C, and is active in two W3C Working Groups: the XForms
and XML Processing Model Working Groups. He holds an MS/CS from the Swiss Institute of
Technology (EPFL) in Lausanne, Switzerland.
Erik Bruchez has extensive experience in the software industry as a software architect and consultant.
As a former employee of Symantec Corporation, he contributed to the VisualCafe for Java product line.
In 1999, he co-founded Orbeon, Inc. (
www.orbeon.com), where he is now an architect of Orbeon
PresentationServer (OPS), an open source web platform for form-based applications that builds on tech-
nologies such as XForms and Ajax. Erik participates in the W3C’s XForms and XML Processing Model
working groups. He is the author of articles about web applications and XML technologies and has been
a speaker at conferences such as JavaOne, ObjectWebCon, and XTech. Erik holds an MS/CS degree from
the Swiss Institute of Technology (EPFL) in Lausanne, Switzerland. He spends most of his time between
Switzerland and California and can be reached by email at

Joe Fawcett started programming in the seventies and briefly worked in IT after leaving full-time educa-
tion. He then pursued a more checkered career before returning to software development in 1994. In
2003 he was awarded the title of Microsoft Most Valuable Professional in XML for community contribu-
tions and technical expertise. He currently works in London as senior developer for FTC Kaplan Ltd, a
leading international provider of accountancy and business training.
Danny Ayers is a freelance developer, technical author, and consultant specializing in cutting-edge Web
technologies. His motivation is the belief that with a little encouragement, the Web can be significantly
more useful and interesting than it is now. He’s been a blogger for some five years (
http://danny
ayers.com
), with a tendency to post material relating to the Semantic Web or cat photos.
Technical Editor
Micah Dubinko is an experienced software architect and writer working for the
Mobile Platform group at Yahoo! Inc. He has been programming since the third grade—at the time on a

computer with only 2K of memory. Micah served as an editor and author of the W3C XForms specifica-
tion, publishing a book in print and online, and eventually being awarded the InfoWorld Innovators
2004 award for his effort. Since then, he has contributed to and edited numerous Web 2.0 books and
articles. His blog is at
o/blog/. Micah lives with his wife and two daughters
in Silicon Valley.
01_087889 ffirs.qxp 10/19/06 3:55 PM Page vi
Credits
SeniorAcquisitions Editor
Jim Minatel
Development Editor
Sara Shlaer
Technical Editor
Micah Dubinko
Production Editor
Felicia Robinson
Copy Editor
Michael Koch
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Project Coordinators
Ryan Steffen
Jennifer Theriot
Graphics and Production Specialists

Carrie A. Foster
Denny Hager
Jennifer Mayberry
Barbara Moore
Heather Ryan
Alicia B. South
Quality Control Technician
John Greenough
Proofreading
Techbooks
Indexing
Infodex Indexing Services, Inc.
01_087889 ffirs.qxp 10/19/06 3:55 PM Page vii
01_087889 ffirs.qxp 10/19/06 3:55 PM Page viii
Contents
Foreword xvii
Acknowledgments xix
Introduction xxi
Chapter 1: Hello Web 2.0 World 1
Introducing BuzzWatch 1
Charting the Landscape 4
Exploring Behind the Scene 6
Making BuzzWatch a Better Web Citizen 24
Making BuzzWatch More Maintainable 28
Applying the Final Touch 33
Conclusion 35
Chapter 2: Page Presentation 37
Creating Clean and Simple Pages 37
Producing Valid HTML 38
Using Cascading Style Sheets 40

Choosing Appropriate Elements 41
From HTML to XHTML 42
XHTML 1.0 43
XHTML 1.1 43
Why Use XHTML? 44
Differences from HTML 45
The Document Object Model 47
DOM Levels 49
DOM API Overview 49
DOM API Reference 51
Cascading Style Sheets 51
Rounded Corners 52
Tabs 54
Tools 55
The DOM Inspector for Firefox 55
The Web Developer Toolbar for Firefox 57
The Internet Explorer Developer Toolbar 58
DevBoi for Firefox 59
Summary 60
02_087889 ftoc.qxp 10/19/06 3:56 PM Page ix
x
Contents
Chapter 3: JavaScript and Ajax 61
JavaScript: Understanding Lesser-Known but Crucial Features 61
The undefined Value and Type 62
The === Operator 64
Iterating with for-in 65
Functional Programming 66
Function Arguments 67
JavaScript Optimizations 69

Reducing JavaScript Download Time 69
Keep DOM Updates to a Minimum 70
Ajax 70
It’s All About the User Experience 71
XMLHttpRequest History 71
XMLHttpRequest Example 72
Yahoo! UI Library 75
Google Web Toolkit 78
Handling Memory Leaks 79
Summary 81
Chapter 4: Design Principles 83
Common Design Issues 84
Bookmarks 84
Navigation 88
Minimizing Traffic 89
Support for Down-Level Devices 93
Accessibility Requirements and Guidelines 94
Summary 109
Chapter 5: What’s Next for Web 2.0? 111
XSLT and XPath 111
XSLT Hello World Example 112
More XSLT 114
XSLT Styles 117
More XSLT 119
Using XSLT in a Browser 122
SVG 124
SVG Hello World Example 126
Styling SVG 130
More SVG 132
02_087889 ftoc.qxp 10/19/06 3:56 PM Page x

xi
Contents
XForms 142
XForms Hello World Example 143
Styling XForms 147
More XForms Examples 151
What’s Next for HTML 161
The W3C Proposals 162
The WHATWG Counterproposals 163
Comparing XHTML 2.0 and HTML 5 164
Summary 165
Chapter 6: Rich Client Alternatives 167
From Browsers to Rich Clients 167
Browser Drawbacks 168
A Solution — Rich Clients 169
Rich Clients Today 169
Comparing Rich Client Frameworks 169
OpenLaszlo 170
XUL 179
XAML 186
Summary 190
Chapter 7: HTTP and URIs 193
How the Web Was Won 193
Web 1.0: HTML, URLs, and HTTP 194
Under the Hood 195
URLs and URIs 196
Dangers of Hidden Code 199
What Does a Web Server Really Do? 199
The Web Is Two-Way 200
The Web Model and REST 200

Resources 201
Representations 201
State 202
Transfer: Using HTTP Methods 203
Considerations for Building an HTTP Service 204
Media Types 205
Resources of Interest 205
Required Representations 206
Server Response 207
02_087889 ftoc.qxp 10/19/06 3:56 PM Page xi
xii
Contents
What’s on the Wire? 208
Reference Toolkit 208
An HTTP Example 208
More Representations 212
Content Negotiation 214
Watching Messages with HTTPTracer 215
Summary 219
Chapter 8: XML and Its Alternatives 221
XML 221
The Basics of XML 221
XML Namespaces 225
Unicode and Character Encodings 227
Dealing with Binary Data 229
Features of XML You Usually Won’t Need 230
Datatypes 231
Schema Languages 232
XSLT and XPath 233
Other XML Technologies 234

Existing Data Formats and Protocols 235
APIs 235
Alternatives to XML 235
JSON 236
JavaScript 238
HTML 238
Other Formats 240
Summary 241
Chapter 9: Syndication 243
Some Syndication Basics 243
Microcontent 244
The Feed 244
The Syndication Process 246
Syndication Formats 246
RSS 2.0: Simple Content 247
RSS 1.0: Resource Description 251
RSS 1.0 Specifications and Modules 256
Atom: Best of Both Worlds? 257
Atom Specifications and Extensions 261
02_087889 ftoc.qxp 10/19/06 3:56 PM Page xii
xiii
Contents
Comparing Elements Across Formats 261
Enclosures and Podcasting 262
Summary 263
Chapter 10: Microformats 265
The Basics of Microformats 266
CSS and Microformats 267
Semantic HTML 269
Content, Presentation, and Data 269

Disambiguation 269
Coverage 271
Standards Org 2.0 273
Creating Microformat Documents 275
Example: Events Timeline 275
Summary 285
Chapter 11: Combining Protocols to Build Web Services 287
Clarifying Web Services 287
REST Services 288
A Sample Application 288
The Atom Publishing Protocol 292
REST Services in the Wild 292
More Resources on REST 294
WS-* Services 295
WS-* Services and SOAP 295
WS-* Services and WSDL 299
The WS-* Stack 301
REST versus WS-* 303
SOAP 303
WSDL 304
Tool Support 305
Summary 307
Chapter 12: Serving XML over HTTP 309
How Is Serving HTML Different? 309
Media Types 309
Character Encoding 310
Serving Well-Formed XML 310
Serving Static Content 310
02_087889 ftoc.qxp 10/19/06 3:56 PM Page xiii
xiv

Contents
Serving Dynamic Content 312
Principles 312
Serving XML with Java 313
Serving XML with ASP.NET and C# 317
Serving XML with Ruby on Rails 321
Serving XML with PHP, Perl, Python, and More 322
Using Server-Side XSLT 322
Using an XML Platform 325
XQuery and XML Databases 328
Serving XML with eXist 329
WebDAV and Subversion 331
Serving JSON 332
Summary 332
Chapter 13: Databases and Non-XML Sources 333
Dealing with Non-XML Sources 333
Converting Relational Data to XML 334
Server-Side Transformation Using SQL Server 339
Client-Side Transformation Using ADO.NET 343
Using Oracle XSQL 348
Converting Binary Data to XML 358
A Manual Conversion 358
Automating the Conversion 363
Summary 370
Chapter 14: Creating Syndication Channels 371
A Simple Atom Service 371
User Interfaces 372
Application Architecture 374
Abdera Atom Toolkit 374
Code Overview 375

Running the Application 388
Compiling and Deploying the Application 388
Considerations for Going Live 389
Adding E-mail Support 389
Understanding the Mail Support Architecture 391
Setting Up a Local Mail Server 391
Using the MailClient Class 393
The MessageReader Interface 396
MailEntryCollector 396
Summary 400
02_087889 ftoc.qxp 10/19/06 3:56 PM Page xiv
xv
Contents
Chapter 15: Mashups, HTML Scraping, and Web Services 401
Popular Examples: Mapping Mashups 402
Why Use Mashups? 404
The Business Model of Mashups 406
Screen Scraping 407
Benefits and Drawbacks 407
Playing Fair 408
Downloading the Page 408
Analyzing the Page 409
A Simple Screen Scraping Example 410
Creating Feeds 411
Deploying on Your Server 414
Deploying Through an External Service 415
Mapping and Badges 415
Badges 416
Google Maps 417
Summary 419

Chapter 16: Implementing and Maintaining Your URI Space 421
Future-Proofing Your URIs 422
Technology Agnosticism 422
Hierarchies and Collections 423
Trailing Slashes and Location Independence 424
Managing Change in Your URI Space 425
The Basics of HTTP Redirection 425
Permanently Redirecting Resources 426
Temporarily Redirecting Resources 426
Redirection Methods You Should Not Use 427
Server-Side Redirection 428
Your URI Mapping Toolbox 428
Java Servlets 428
Apache mod_alias and mod_rewrite 429
ASP .NET and IIS 433
Summary 433
Chapter 17: Podcasting and Serving Multimedia 435
The Formats Labyrinth 436
Descriptive Formats 436
Container and Encoding Formats 447
02_087889 ftoc.qxp 10/19/06 3:56 PM Page xv
xvi
Contents
Protocols 454
Multicast 455
Unicast 455
Choosing a Protocol 456
Summary 457
Chapter 18: Security 459
What Is Security? 459

Resource Security 459
Message Security 460
Lessons Learned from History 461
The Layered Approach 461
Authentication and Authorization 462
Authentication and Authorization in IIS and ASP.NET 462
Different Authentication Methods in IIS and ASP.NET 464
Authentication and Authorization in Apache 466
Message Encryption 467
Symmetric Encryption 467
Public Key Infrastructure 468
Message Digests 469
Digital Certificates 469
Secure Sockets Layer 470
The Stages of in an SSL Communication 471
Setting Up SSL in IIS 471
Setting Up SSL in Apache 475
Code Security 479
General Principles 479
Web Services Security 482
Using Web Services Security 483
How the Web Service Works 485
Adding Policy 486
Adding the Custom Authentication 487
Creating a Client 490
Improving Security 493
Summary 494
Index 495
02_087889 ftoc.qxp 10/19/06 3:56 PM Page xvi
Foreword

It is a very different world now than the one that Flickr was born into. For one thing, we weren’t aware
back then that we were living in a Web 1.0 world (much as those living in the Middle Ages didn’t con-
sider themselves to be in any kind of middle). But a lot of things had already transpired to lead the way
into the brave new world we now live in, the Web 2.0 world. For one thing, online social interactions
had become, once again, the norm. Blogging had stopped being a weird, fringe activity, and become
something even Uncle Leonard would do. Friendster and its many imitators had made it normal to have
an online digital identity. And unlike the early days, more and more and more people were online. In
2003 it was announced that over 50 percent of all Internet users were now on broadband, and no longer
on dial-up. The network was ubiquitous, the infrastructure was there: the stage for Web 2.0 was set.
One of the significant things that Flickr and its ilk ushered forward was what we used to refer to as
“remote scripting” or “DHTML jujitsu,” but which eventually came to be known as Ajax. Readers of this
book will probably have watched its evolution with interest. The web was always described as read/
write, but hitherto, the “write” aspect was largely constrained to form fields and associated with slow
and yawn-inducing page reloads. The flexibility of Ajax, its responsiveness to user actions and inputs,
instantly made the web easier and more enjoyable to use. Flickr users didn’t necessarily understand
what we were doing, or how, just that they liked it very much. This book is very much about how,
through technology, you can capture and delight your users.
I want to thank the authors, and the editors, for writing this excellent guide to the technologies support-
ing this exciting time in web development. Web 2.0 is really a developer’s paradise! I look forward to
seeing the results the readers of this book will bring into being.
Caterina Fake
Co-founder of Flickr and Senior Director, Technology Development, Yahoo! Inc.
03_087889 flast.qxp 10/19/06 3:56 PM Page xvii
03_087889 flast.qxp 10/19/06 3:56 PM Page xviii
Acknowledgments
Our thanks to Jim Minatel, who has believed in this book from the very beginning and fought to make it
happen, our editor Sara Shlaer for her friendly guidance, and our tech reviewer Micah Dubinko who has
tracked down the errors and inconsistencies in our prose and code.
I am very grateful to the friends who helped me to build the outline of this book and to my co-authors for
their patience and acceptance of my role as a “benevolent dictator setting the ground rules”: they are

responsible for the good things in this book but I am the only one responsible for the flaws you might find
in its structure! I’d also like to thank Robin Berjon for his guidance on the chapter about multimedia.
E. van der V.
My thanks to Eric van der Vlist for his organizational abilities, to my other co-authors for their support,
and to Sara Shlaer for editing my painful prose uncomplainingly or out of earshot. A big thank you to
Jim Minatel for originally inviting me to write for Wiley, thereby helping me to achieve a long-standing
ambition.
J.F.
Many thanks to Jim Minatel for giving me the call, to Sara Shlaer for wonderfully clear and helpful
editing, and to them both for their patience through my periods of procrastination. Thanks, too, to
the authors with whom it has been a great privilege to work, in particular to Eric van der Vlist for pro-
viding the vision. Finally, thanks to Micah Dubinko for sharing his expertise with a gentle touch while
tech-reviewing.
D.A.
03_087889 flast.qxp 10/19/06 3:56 PM Page xix
03_087889 flast.qxp 10/19/06 3:56 PM Page xx
Introduction
The common trend behind the most successful recent Web applications is an innovative usage and integra-
tion of many different mature technologies. This trend is known under the oft-hyped and controversial term
Web 2.0. Whatever your feelings regarding this term, whether you think that it is the greatest invention
since sliced bread, that this is an irritating buzzword, or, like I personally do, that it is both, it can’t be
denied that after years of relative stagnation, web development is moving on and has become fun again.
Web 2.0 is before everything else about finding new ways to make a number of existing technologies
work together. There is no single Web 2.0 technology and for professional developers, this represents a
new challenge. In recent years, there has been a tendency to specialize in Web development. I know a
number of experts in some of the technologies that are the technical foundation of Web 2.0 (HTML, CSS,
HTTP, JavaScript, XML, server side programming, and so on) who have a very limited knowledge of the
other technologies that make a successful Web 2.0 application, and sometimes don’t even see why they
should care. Of course, Web 2.0 applications may often need such highly specialized experts, but more
than anything else, they need developers who are perhaps not experts in all these areas, but understand

enough of each technology to get the big picture, and who understand the division of roles between
them and the trade-offs that will be made. It makes no sense to code in HTML or JavaScript what can
easily be done with CSS, to reinvent an exchange format due to lack of XML fluency, or to implement
server side what can be done by a single URL rewriting rule in the Web server configuration file.
To make things worse, most of the books, resources, and training materials available follow this rule of
over-specialization, and you’ll find a number of good books on each of the individual technologies used
by Web 2.0 applications. However, you’ll find very few resources introducing all these technologies
together at a professional level. This does not only mean that if you want to get the level of knowledge
required to develop Web 2.0 applications you’ll have to buy and read a complete bookshelf, but also that
after doing so you may still miss a clear vision of how they work together.
Our goal is that this book will fill this gap and give you both the initial knowledge that you need in each
technology and the big picture so that you can really understand how Web 2.0 applications work behind
the scene and how they are developed.
Who This Book Is For
This book is for professional developers involved in Web 2.0 projects (the next section offers criteria to
check if a Web project is Web 2.0). No specific technical knowledge is required, but we assume a basic
familiarity, if not detailed knowledge of HTML, CSS, JavaScript, and XML. We won’t explain either what a
programming language is, how an if/then/else statement works, or the principles of computer networks.
The different technologies on which Web 2.0 is based are introduced at a fairly basic level and should not
require prior knowledge. If you know everything about one of them you can of course skip the corre-
sponding chapter, but we invite you rather to at least quickly scan through it. We have tried to introduce
every technology in the context of Web 2.0 applications, to explain its links with the other technologies
and to give a number of pointers to other chapters that you could miss if you skip a chapter.
03_087889 flast.qxp 10/19/06 3:56 PM Page xxi
xxii
Introduction
What This Book Covers
It would be difficult to explain what this book covers without defining what Web 2.0 is. If you search
around for definitions of the term Web 2.0, you’ll find a number of apparently unrelated types of defini-
tions: Web 2.0 is either a collaborative web where the content is created by the users (this aspect is often

called the
social layer of Web 2.0), or a web where the network is the platform or web that uses funky
technologies such as Ajax or Ruby on Rails (this one is called the
technical layer of Web 2.0). The coexistence
of these definitions together with a number of other less popular ones can give the feeling that the term
Web 2.0 is nothing more than a buzz word to designate anything somewhat new in web development.
This isn’t totally true, and these definitions are more closely tied together than you might think.
Before the burst of new ideas that we call Web 2.0, the Web seemed to have reached a stage where its
growth would slowly start declining. In many countries, the proportion of people with web access was
already high enough so that the growth rate could only decrease. Furthermore, the production of web
content seemed deemed to be increasingly controlled by traditional media producers, and the alliance
between AOL and Time Warner was showing that the web industry had started its consolidation phase.
On the technical side, there seemed to be very few exciting perspectives in developing HTML web pages
used by web browsers strongly dominated by Internet Explorer after Microsoft announced that their
browser wouldn’t be developed further. In other words, the Web was in danger of become boring for
both users and developers.
Web 2.0 is the demonstration that these limitations were artificial and self-imposed by a lack of vision of
the web potential, both socially and technically. Socially, the Web had become a read-only medium where
most of the content was published and broadcast pretty much like in conventional media. This hadn’t
always been the case: the Web was originally designed as a medium where scientists could easily share
their documents. This was still the case in the early 1990s, when the Web was largely composed of home
pages and link pages edited and published by web users for the benefit of other web users. This was
possible because the technology was simple (the first versions of HTML were text-only, without style nor
even pictures), and because the target audience was able and willing to edit web pages without much
tool support. During the next iterations of web technologies, user expectations in term of presentation
increased, the technologies became significantly more complicated as they evolved, new technologies
were added to the stack and the whole process of web development was obscured by the browser war
between Netscape and Microsoft that gave birth to incompatible behaviors between browsers. At the
same time, the audience expanded beyond the small circle of people willing to learn these technologies
to publish their own content. As a result, the Web became for most of its users a read-only web, rather

than the cooperative venture it had been originally.
The social layer of Web 2.0 is about making the Web a read/write web again. For some, this goal is
motivated by philanthropic or political reasons: everyone should be able to express his or her ideas.
For others, the motivation is financial: if the growth of the number of web readers is deemed to slow
down, the growth of the Web can only be fueled by the growth of the number of people that create con-
tent on the Web. The business models of Web 2.0 sites differ on the way to convert content into actual
revenues, but they share the fact that their
content is created by their users, and this is the most distinctive
characteristic of a Web 2.0 site.
The ability of using the Web as a platform can be seen as the
architectural layer of Web 2.0. This architec-
tural layer is a consequence of the social layer: if you want to give write access to all your users you can’t
rely on anything that isn’t installed (or installable) on any platform they might be using. That limits the
03_087889 flast.qxp 10/19/06 3:56 PM Page xxii
xxiii
Introduction
prerequisite for Web 2.0 applications to a relatively recent version of a web browser. Furthermore, due to
most needed security constraints, web applications have very limited access to files and data stored on
their users’ computers. That means that Web 2.0 applications have not much alternative to considering
that the platform on which they run is the Web!
The technical layer is also a consequence of the social and architectural layers: the ability to write on the
Web that has been limited by the growing complexity of the web technology can only be given back to
web users by using more technology. Fortunately, the generation of technologies introduced in the late
1990s (CSS, JavaScript, XML, and similar technologies) has become mature and available on a large
majority of browsers, and they can be used to develop more convivial web applications that focus on
making it easy for users to create and publish content. In other words, the flurry of Ajax, JavaScript, and
XML technologies that characterize most of Web 2.0 applications are needed to lower the barrier to entry
in the circle of web publisher that Web 2.0 applications try to enlarge.
Note that without this social layer, a web application can’t always pretend to be Web 2.0, even if it has all
its technical characteristics. My Internet service provider has recently redeveloped the organization’s

website. In the documentation section, they have replaced HTML links to documentation by a sophisti-
cated drag-and-drop mechanism: to view a piece of documentation, users need to drag its icon to a box
located at the top of the page. This is an example where using Web 2.0 techniques is not only useless but
counterproductive: most users, including the author of this introduction, lose a lot of time before they
understand how they can reach the documentation. Furthermore, in that case, the technologies do not
enable people to contribute to the site, which can’t pretend to be any more Web 2.0 that its previous ver-
sion. To claim to be Web 2.0, they should have tried to make users contribute. That could have been done
by making their sites editable like Wikipedia, or letting users add their notes to the documentation like
the PHP documentation site (
www.php.net/manual/en/). Neither Wikipedia nor php.net uses a lot of
fancy bells and whistles, but both heavily rely on their users to create their content and Wikipedia is
mentioned in all the lists of top Web 2.0 sites.
This book focuses on the technical layer of Web 2.0 and covers each of the technologies that are used by
Web 2.0 projects, both client and server side, but ultimately the most important question is not whether
you use the techniques described in this book but whether the site that you are developing is read-only or
whether your users contribute to its content. It’s also important to note that content here is meant to be con-
tent at large. Many Web 2.0 sites do not rely on their users for creating all their content but only to enrich
their content. A significant example is Amazon.com. Of course, the main content on the Amazon.com
web site comes from the company’s own database, however, what makes the difference between the
Amazon.com site and other similar sites is how it integrates content from Amazon.com partners and users.
Users are not only welcome to publish reviews, they contribute to the site each time they buy a new item
and even by browsing the site: these simple actions are analyzed and they are used to publish tips such as
the “What do customers ultimately buy after viewing items like this?” that is currently displayed if you
browse the description of this book on Amazon.com. This is perhaps the most convincing example of a low
entry barrier to contributing to a site’s content!
How This Book Is Structured
Web 2.0 applications are client/server applications, and this has determined the structure of this book. It
is composed in three parts to describe how all this work client side, server side, and in between. The log-
ical order to describe these three parts would have been to start describing the protocols and formats use
03_087889 flast.qxp 10/19/06 3:56 PM Page xxiii

xxiv
Introduction
to communicate between clients (usually web browsers) and servers and to follow with the descriptions
of how that was implemented client and server side. However, we thought that it would have been very
tedious to start by describing protocols and exchange formats before you can see what they are used for.
Our experience is that most people learn quicker and better if they have concrete applications in mind,
so the first part of this book is about client-side technologies, because the browser is where web applica-
tions are most visible. Protocols and formats come second, and the last part is about server programming.
Although we believe that this structure will be, at the end of the day (or should I say, at the end of the
book), beneficial for most of our readers, it leads to a number of forward references. For example, HTTP
and XML are mentioned a number of times in Part I, but they are only discussed in detail in Part II.
We’ve written Part I while trying to avoid needing an advanced knowledge of the topics described in
Part II, but also assuming that most of our readers would have had a minimal level of exposure to these
topics. If that’s not the case or if you find these forward references just too annoying, you are welcome to
read the three parts of this book starting with Part II and following with Part I and Part III.
The structure of this book is:
❑ Chapter 1, “Hello Web 2.0 World,” follows a simple Web 2.0 sample application to present the
sequence of exchanges between a web server and a browser and show examples of code imple-
menting these exchanges. After this chapter, you should have a better understanding of the
roles of the technologies covered by this book.
❑ Part I, “Client Side,” presents the technologies used client side to create Web 2.0 applications.
This includes (X)HTML and CSS (Chapter 2), JavaScript and Ajax (Chapter 3), design principles
(Chapter 4), technologies which should become major client-side technologies in the next few
months or years (Chapter 5), and rich client alternatives (Chapter 6).
❑ Part II, “Between Clients and Servers,” is about the protocols and formats used to exchange
information between web clients and servers. It covers HTTP and URIs, which are the real
basis of the World Wide Web (Chapter 7), XML and its alternatives (Chapter 8), syndication
(Chapter 9), microformats (Chapter 10), and web services (Chapter 11).
❑ Part III, “Server Side,” describes what you need to know about server-side programming,
including how to serve XML over HTTP (Chapter 12), how to use non-XML data sources

(Chapter 13), how to create syndication channels (Chapter 14), building mashups, that is, how
to aggregate information from multiple sources (Chapter 15), how to implement and maintain
your URI space (Chapter 16), issues specific to serving multimedia (Chapter 17), and what you
should know about security (Chapter 18).
What You Need to Use This Book
If Web 2.0 is about using the Web as a platform, you’ll obviously need this platform to use this book.
This means that you will need both a web server and a web browser to run the examples from this book.
This book was written by authors working on Windows XP, Linux, and Max OS X and we’ve been care-
ful to be as neutral as possible regarding the operating system on which the examples can run. With the
exception of a few samples which are Microsoft-specific (such as the XAML samples in Chapter 6), it
should be possible to run the samples presented in this book on a platform running any of these operat-
ing systems on a single machine running a local web server unless you prefer using separate platforms
for your browser and your server.
03_087889 flast.qxp 10/19/06 3:56 PM Page xxiv

×