Core Web Programming Volumes I II Includes index 2nd ed Edition Hall download pdf
Core Web Programming Volumes I II Includes index 2nd ed Edition Hall download pdf
com
https://ebookfinal.com/download/core-web-programming-
volumes-i-ii-includes-index-2nd-ed-edition-hall/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookfinal.com/download/db2-developer-s-guide-includes-
index-5th-ed-edition-mullins/
ebookfinal.com
https://ebookfinal.com/download/mcgraw-hill-s-praxis-i-and-ii-2nd-
ed-2nd-edition-laurie-rozakis/
ebookfinal.com
https://ebookfinal.com/download/core-servlets-and-javaserver-pages-
advanced-technologies-2nd-edition-marty-hall/
ebookfinal.com
https://ebookfinal.com/download/web-programming-with-dart-1st-ed-
edition-moises-belchin/
ebookfinal.com
Joomla 1 5 a user s guide building a successful Joomla
powered website Description based on print version record
Includes index 2nd ed Edition North
https://ebookfinal.com/download/joomla-1-5-a-user-s-guide-building-a-
successful-joomla-powered-website-description-based-on-print-version-
record-includes-index-2nd-ed-edition-north/
ebookfinal.com
https://ebookfinal.com/download/programming-microsoft-asp-
net-2-0-core-reference-2005-ed-edition-dino-esposito/
ebookfinal.com
https://ebookfinal.com/download/world-of-warcraft-programming-2nd-
edition-james-whitehead-ii/
ebookfinal.com
https://ebookfinal.com/download/murach-s-asp-net-4-web-programming-
with-c-2010-4th-ed-edition-boehm/
ebookfinal.com
CORE
Web Programming
MARTY HALL
LARRY BROWN
10 9 8 7 6 5 4 3 2 1
ISBN 0-13-089793-0
INTRODUCTION XXXIII
Real Code for Real Programmers xxxiv
How This Book Is Organized xxxv
Conventions xxxviii
About the Web Site xxxix
About the Authors xxxix
ACKNOWLEDGMENTS XLI
Part 1
THE HYPERTEXT MARKUP LANGUAGE 2
C hap t er 1
DESIGNING WEB PAGES WITH HTML 4.0 4
1.1 The HyperText Markup Language 5
1.2 HTML 4.0 and Other HTML Standards 7
1.3 Steps to Publish a Document on the Web 9
Create the Document 9
iii
iv Contents
ChapTer 2
BLOCK-LEVEL ELEMENTS IN HTML 4.0 28
2.1 Headings 30
2.2 Basic Text Elements 32
Basic Paragraphs 32
Paragraphs with White Space Preserved 34
Indented Quotations 35
Addresses 35
2.3 Numbered, Bulleted, and Indented Lists 35
Numbered Lists 36
Bulleted Lists 39
Definition Lists 40
2.4 Tables 41
The Basic Table Structure 42
Defining Table Rows 46
Table Headings and Data Cells 48
Grouping Table Contents 50
2.5 Fill-Out Forms 54
2.6 Miscellaneous Block-Level Elements 54
2.7 Summary 57
Contents v
ChapTer 3
TEXT-LEVEL ELEMENTS IN HTML 4.0 58
3.1 Physical Character Styles 59
3.2 Logical Character Styles 64
3.3 Specifying Hypertext Links 67
3.4 Embedded Images 70
Animated GIFs 71
The IMG Element 71
3.5 Client-Side Image Maps 75
3.6 Embedding Other Objects in Documents 79
Embedded Applets 80
Embedded Video, Audio, and Other Formats with Plug-ins 82
Embedded ActiveX Controls 83
Embedded Scrolling Text Banners 85
3.7 Controlling Line Breaks 86
3.8 Summary 87
Chapter 4
FRAMES 88
4.1 Frame Document Template 90
4.2 Specifying Frame Layout 91
4.3 Specifying the Content of Frame Cells 96
Examples 98
4.4 Targeting Frame Cells 100
Predefined Frame Names 103
4.5 Solving Common Frame Problems 103
Bookmarking Frames 104
Printing Frames 104
Updating Multiple Frame Cells Simultaneously 105
Preventing Your Documents from Being Framed 108
Creating Empty Frame Cells 109
4.6 Inline Frames 109
4.7 Summary 113
vi Contents
Chapter 5
CASCADING STYLE SHEETS 114
5.1 Specifying Style Rules 116
5.2 Using External and Local Style Sheets 118
External Style Sheets 119
The STYLE Element and JavaScript Style Sheets 120
Inline Style Specification 121
5.3 Selectors 121
HTML Elements 122
User-Defined Classes 123
User-Defined IDs 124
Anchor Pseudoclasses 124
5.4 Cascading: Style Sheet Precedence Rules 125
5.5 Font Properties 126
5.6 Foreground and Background Properties 132
5.7 Text Properties 135
5.8 Properties of the Bounding Box 139
Margins 140
Borders 141
Padding 142
Bounding Box Display Types 143
5.9 Images and Floating Elements 143
5.10 List Properties 146
5.11 Standard Property Units 147
Lengths 147
Colors 147
5.12 Layers 148
Specifying Layers with the LAYER and ILAYER Elements 149
Specifying Layers with Style Sheets 153
5.13 Summary 157
Contents vii
Part 2
JAVA PROGRAMMING 158
Chapter 6
GETTING STARTED WITH JAVA 160
6.1 Unique Features of Java 162
Java Is Web-Enabled and Network Savvy 162
Java Is Cross-Platform 166
Java Is Simple 168
Java Is Object Oriented 169
Java Is Rich with Powerful Standard Libraries 170
6.2 Myths About Java 171
Java Is Only for the Web 172
Java Is Cross-Platform 172
Java Is Simple 174
Java Is Object Oriented (the One True Way of Programming) 174
Java Is the Programming Language for All Software Development 175
6.3 Java Versions 175
Which Version Should You Use? 177
Whichever Version You Use 177
6.4 Getting Started: Nuts and Bolts 178
Install Java 178
Install a Java-Enabled Browser 179
Bookmark or Install the On-Line Java API 180
Optional: Get an Integrated Development Environment 180
Create and Run a Java Program 181
6.5 Some Simple Java Programs 182
The Basic Hello World Application 182
Command-Line Arguments 183
The Basic Hello World (Wide Web) Applet 183
Applet Customization Parameters 185
6.6 Summary 187
viii Contents
Chapter 7
OBJECT-ORIENTED PROGRAMMING IN JAVA 190
7.1 Instance Variables 191
7.2 Methods 194
7.3 Constructors and the “this” Reference 196
Static Initialization Blocks 199
7.4 Destructors 199
7.5 Overloading 200
7.6 Public Version in Separate File 204
7.7 Javadoc 209
Javadoc Tags 211
Javadoc Command-Line Arguments 213
7.8 Inheritance 216
7.9 Interfaces and Abstract Classes 221
7.10 Packages, Classpath, and JAR Archives 230
The CLASSPATH 233
7.11 Modifiers in Declarations 236
Visibility Modifiers 236
Other Modifiers 238
7.12 Summary 239
Chapter 8
BASIC JAVA SYNTAX 242
8.1 Rules of Syntax 243
8.2 Primitive Types 245
Primitive-Type Conversion 247
8.3 Operators, Conditionals, Iteration 248
Arithmetic Operators 248
Conditionals 249
Loops 255
8.4 The Math Class 259
Constants 259
Contents ix
Chapter 9
APPLETS AND BASIC GRAPHICS 304
9.1 What Are Applets? 305
9.2 Creating an Applet 306
Template for Applets 307
Template for HTML 307
9.3 An Example Applet 309
Redrawing Automatically 311
Reloading Applets During Development 311
9.4 The Applet Life Cycle 312
9.5 Other Applet Methods 314
9.6 The HTML APPLET Element 320
9.7 Reading Applet Parameters 322
Reading Applet Parameters: An Example 323
9.8 HTML OBJECT Element 326
9.9 The Java Plug-In 328
9.10 Graphical Applications 331
9.11 Graphics Operations 332
Drawing Operations 333
Colors and Fonts 336
Drawing Modes 336
Coordinates and Clipping Rectangles 337
9.12 Drawing Images 337
Loading Applet Images from Relative URLs 338
Loading Applet Images from Absolute URLs 340
Loading Images in Applications 342
9.13 Preloading Images 344
9.14 Controlling Image Loading: Waiting for Images and Checking
Status 348
9.15 Summary 355
Contents xi
Chapter 10
JAVA 2D: GRAPHICS IN JAVA 2 358
10.1 Getting Started with Java 2D 360
Useful Graphics2D Methods 363
10.2 Drawing Shapes 366
Shape Classes 367
10.3 Paint Styles 371
Paint Classes 372
Tiled Images as Fill Patterns 375
10.4 Transparent Drawing 378
10.5 Using Local Fonts 381
10.6 Stroke Styles 383
Stroke Attributes 384
10.7 Coordinate Transformations 390
Shear Transformations 393
10.8 Other Capabilities of Java 2D 394
10.9 Summary 395
Chapter 11
HANDLING MOUSE AND KEYBOARD EVENTS 398
11.1 Handling Events with a Separate Listener 400
Drawing Circles 402
11.2 Handling Events by Implementing a Listener Interface 404
11.3 Handling Events with Named Inner Classes 406
11.4 Handling Events with Anonymous Inner Classes 407
11.5 The Standard Event Listeners 409
11.6 Behind the Scenes: Low-Level Event Processing 415
11.7 A Spelling-Correcting Textfield 418
11.8 A Whiteboard Class 421
A Better Whiteboard 423
11.9 Summary 425
xii Contents
Chapter 12
LAYOUT MANAGERS 426
12.1 The FlowLayout Manager 428
FlowLayout Constructor Options 429
Other FlowLayout Methods 429
12.2 The BorderLayout Manager 430
BorderLayout Constructor Options 432
Other BorderLayout Methods 432
12.3 The GridLayout Manager 433
GridLayout Constructor Options 434
Other GridLayout Methods 435
12.4 The CardLayout Manager 436
CardLayout Constructor Options 440
Other CardLayout Methods 440
12.5 GridBagLayout 441
The GridBagConstraints Object 442
Example 444
GridBagLayout Constructor Options 448
Other GridBagLayout Methods 448
12.6 The BoxLayout Manager 449
BoxLayout Constructor Options 452
Other BoxLayout Methods 453
12.7 Turning Off the Layout Manager 454
12.8 Effective Use of Layout Managers 455
Use Nested Containers 456
Turn Off the Layout Manager for Some Containers 459
Adjust the Empty Space Around Components 461
12.9 Summary 464
Contents xiii
Chapter 13
AWT COMPONENTS 466
13.1 The Canvas Class 468
Creating and Using a Canvas 469
Example: A Circle Component 469
13.2 The Component Class 472
13.3 Lightweight Components in Java 1.1 479
13.4 The Panel Class 482
Default LayoutManager: FlowLayout 482
Creating and Using a Panel 483
Example: Using a Panel for Grouping 483
13.5 The Container Class 485
13.6 The Applet Class 487
13.7 The ScrollPane Class 487
Creating and Using a ScrollPane 487
Example: ScrollPane with 100-Button Panel 488
13.8 The Frame Class 489
Default LayoutManager: BorderLayout 489
Creating and Using a Frame 490
Frame Examples 491
A Closeable Frame 492
Menus 493
Other Useful Frame Methods 495
13.9 Serializing Windows 497
Writing a Window to Disk 497
Reading a Window from Disk 497
Example: A Saveable Frame 498
13.10 The Dialog Class 501
Creating and Using a Dialog 501
Example: A Quit Confirmation Dialog 502
13.11 The FileDialog Class 504
xiv Contents
Chapter 14
BASIC SWING 562
14.1 Getting Started with Swing 564
Differences Between Swing and the AWT 564
xvi Contents
Chapter 15
ADVANCED SWING 628
15.1 Using Custom Data Models and Renderers 630
15.2 JList 631
JList with a Fixed Set of Choices 631
JLists with Changeable Choices 636
JList with Custom Data Model 639
JList with Custom Renderer 646
15.3 JTree 650
Simple JTree 650
JTree Event Handling 654
15.4 JTable 664
Simple JTable 664
Table Data Models 669
Table Cell Renderers 674
Table Event Handling 676
15.5 Swing Component Printing 680
Printing Basics 681
The Role of Double Buffering 683
xviii Contents
Chapter 16
CONCURRENT PROGRAMMING WITH JAVA THREADS 698
16.1 Starting Threads 700
Mechanism 1: Put Behavior in a Separate Thread Object 700
Mechanism 2: Put Behavior in the Driver Class,
Which Must Implement Runnable 703
16.2 Race Conditions 706
16.3 Synchronization 709
Synchronizing a Section of Code 709
Synchronizing an Entire Method 710
Common Synchronization Bug 710
16.4 Creating a Multithreaded Method 712
16.5 Thread Methods 717
Constructors 718
Constants 719
Methods 719
Stopping a Thread 725
16.6 Thread Groups 727
Constructors 727
Methods 727
16.7 Multithreaded Graphics and Double Buffering 729
Redraw Everything in paint 730
Implement the Dynamic Part as a Separate Component 734
Have Routines Other Than paint Draw Directly 735
Override update and Have paint Do Incremental Updating 737
Use Double Buffering 743
Contents xix
Chapter 17
NETWORK PROGRAMMING 760
17.1 Implementing a Client 762
Example: A Generic Network Client 765
17.2 Parsing Strings by Using StringTokenizer 768
The StringTokenizer Class 768
Constructors 769
Methods 769
Example: Interactive Tokenizer 770
17.3 Example: A Client to Verify E-Mail Addresses 771
17.4 Example: A Network Client That Retrieves URLs 774
A Class to Retrieve a Given URI from a Given Host 775
A Class to Retrieve a Given URL 777
UrlRetriever Output 778
17.5 The URL Class 779
Reading from a URL 779
Other Useful Methods of the URL Class 781
17.6 WebClient: Talking to Web Servers Interactively 783
17.7 Implementing a Server 791
Example: A Generic Network Server 793
Connecting NetworkClient and NetworkServer 797
17.8 Example: A Simple HTTP Server 797
ThreadedEchoServer: Adding Multithreading 802
17.9 RMI: Remote Method Invocation 804
Steps to Build an RMI Application 805
A Simple Example 806
xx Contents
Par t 3
SERVER-SIDE PROGRAMMING 830
Chapter 18
HTML FORMS 832
18.1 How HTML Forms Transmit Data 833
18.2 The FORM Element 838
18.3 Text Controls 843
Textfields 843
Password Fields 845
Text Areas 846
18.4 Push Buttons 848
Submit Buttons 849
Reset Buttons 852
JavaScript Buttons 853
18.5 Check Boxes and Radio Buttons 854
Check Boxes 854
Radio Buttons 855
18.6 Combo Boxes and List Boxes 857
18.7 File Upload Controls 860
18.8 Server-Side Image Maps 862
IMAGE—Standard Server-Side Image Maps 863
ISMAP—Alternative Server-Side Image Maps 865
Contents xxi
Chapter 19
SERVER-SIDE JAVA: SERVLETS 872
19.1 The Advantages of Servlets Over “Traditional” CGI 874
Efficient 874
Convenient 875
Powerful 875
Portable 875
Secure 876
Inexpensive 876
19.2 Server Installation and Setup 876
Obtain Servlet and JSP Software 877
Bookmark or Install the Servlet and JSP API Documentation 878
Identify the Classes to the Java Compiler 878
Package Your Classes 879
Configure the Server 879
Compile and Install Your Servlets 879
Invoke Your Servlets 880
19.3 Basic Servlet Structure 880
A Servlet That Generates Plain Text 882
A Servlet That Generates HTML 883
Simple HTML-Building Utilities 885
19.4 The Servlet Life Cycle 887
The init Method 887
The service Method 888
The doGet, doPost, and doXxx Methods 889
The SingleThreadModel Interface 889
xxii Contents
Chapter 20
JAVASERVER PAGES 964
20.1 JSP Overview 965
20.2 Advantages of JSP 967
Versus Active Server Pages (ASP) or ColdFusion 967
Versus PHP 967
Versus Pure Servlets 967
Versus Server-Side Includes (SSI) 968
Versus JavaScript 968
20.3 JSP Scripting Elements 968
Expressions 969
Scriptlets 972
Declarations 975
Predefined Variables 977
20.4 The JSP page Directive 979
The import Attribute 979
The contentType Attribute 982
The isThreadSafe Attribute 983
The session Attribute 984
The buffer Attribute 984
The autoflush Attribute 984
The extends Attribute 985
The info Attribute 985
The errorPage Attribute 985
The isErrorPage Attribute 985
The language Attribute 985
xxiv Contents
Chapter 21
USING APPLETS AS FRONT ENDS TO
SERVER-SIDE PROGRAMS 1064
21.1 Sending Data with GET and Displaying the Resultant Page 1066
21.2 A Multisystem Search Engine Front End 1067
Contents xxv
Chapter 22
JDBC 1092
22.1 Basic Steps in Using JDBC 1094
Load the Driver 1094
Define the Connection URL 1095
Establish the Connection 1096
Create a Statement 1096
Execute a Query 1097
Process the Results 1097
Close the Connection 1098
22.2 Basic JDBC Example 1098
22.3 Some JDBC Utilities 1105
22.4 Applying the Database Utilities 1114
22.5 An Interactive Query Viewer 1120
Query Viewer Code 1122
22.6 Prepared Statements (Precompiled Queries) 1127
22.7 Summary 1131
xxvi Contents
Chapter 23
XML PROCESSING WITH JAVA 1132
23.1 Parsing XML Documents with DOM Level 2 1134
Installation and Setup 1134
Parsing 1135
23.2 DOM Example: Representing an XML Document as a JTree 1137
23.3 Parsing XML Documents with SAX 2.0 1149
Installation and Setup 1149
Parsing 1150
23.4 SAX Example 1: Printing the Outline of an XML Document 1152
23.5 SAX Example 2: Counting Book Orders 1158
23.6 Transforming XML with XSLT 1164
Installation and Setup 1164
Translating 1165
23.7 XSLT Example 1: XSLT Document Editor 1169
23.8 XSLT Example 2: Custom JSP Tag 1179
23.9 Summary 1187
Par t 4
JAVASCRIPT 1188
Chapter 24
JAVASCRIPT: ADDING DYNAMIC CONTENT TO WEB PAGES 1190
24.1 Generating HTML Dynamically 1193
Compatibility with Multiple Browsers 1197
24.2 Monitoring User Events 1198
24.3 Mastering JavaScript Syntax 1200
Dynamic Typing 1201
Function Declarations 1201
Objects and Classes 1202
Arrays 1208
Contents xxvii
Chapter 25
JAVASCRIPT QUICK REFERENCE 1274
25.1 The Array Object 1275
Constructors 1275
Properties 1276
Methods 1276
Event Handlers 1279
xxviii Contents
Properties 1295
Methods 1295
Event Handlers 1295
25.10 The Hidden Object 1296
Properties 1296
Methods 1296
Event Handlers 1296
25.11 The History Object 1296
Properties 1297
Methods 1297
Event Handlers 1297
25.12 The Image Object 1297
Constructor 1298
Properties 1298
Methods 1299
Event Handlers 1299
25.13 The JavaObject Object 1300
25.14 The JavaPackage Object 1300
25.15 The Layer Object 1300
Constructors 1300
Properties 1301
Methods 1302
Event Handlers 1303
25.16 The Link Object 1304
Properties 1304
Methods 1305
Event Handlers 1305
25.17 The Location Object 1306
Properties 1306
Methods 1307
Event Handlers 1307
xxx Contents
INDEX 1360
Chapter
In late 1995, Marty Hall proposed a new course for the part-time graduate program
in Computer Science at the Johns Hopkins University. The idea was to bring together
the major Web-related topics in a single course dubbed “Distributed Development
on the World Wide Web,” with Java technology as a unifying theme. Students would
look at HTML, Java, HTTP, CGI programming, and JavaScript, with lots of hands-on
projects and no exams. Little did Marty know what he was getting himself into. By
the time the first section was offered in the summer of 1996, the Java tidal wave had
swept through the university and the companies that the students represented.
Shortly after enrollment opened, the class was filled. There were more students on
the waiting list than in the course. Marty got frantic phone calls from students insist-
ing that they absolutely had to be in the course. Several local companies called, ask-
ing for on-site courses. What fun!
However, when Marty went shopping for texts over the next semester or two, he
got a rude surprise. Despite the availability of good books in most of the individual
areas he wanted to cover, Marty found that he needed three, four, or even five sepa-
rate books to get good coverage of the overall material. Similarly, for his day job,
Marty was constantly switching back and forth among the best of the huge stack of
books he had accumulated and various on-line references. Surely there was a better
way. Shouldn’t it be possible to fit 85 percent of what professional programmers use
in about 35 percent of the space, and get it all in one book?
That was the genesis of the first edition of Core Web Programming. The book was
very popular, but the industry has been rapidly moving since the book’s release.
Browsers moved from HTML 3.2 to 4.0. The Java 2 platform was released, providing
greatly improved performance and graphics libraries suitable for commercial-quality
xxxiii
xxxiv Introduction
applications. JSP 1.0 came along, resulting in an explosion of interest in both servlets
and JSP as an alternative to CGI and to proprietary solutions like ASP and Cold-
Fusion. XML burst upon the scene. The server equalled or even surpassed the desk-
top as the biggest application area for the Java programming language.
Wow. And demand has only been growing since then. Although readers were
clamoring for a new edition of the book, it was just too much for Marty to handle
alone. Enter Larry Brown, with broad development and teaching experience in Java
and Web technologies, and with particular expertise in the Java Foundation Classes,
multithreaded programming, RMI, and XML processing with Java. Larry teamed up
with Marty to totally update the existing material to HTML 4, CSS/1, HTTP 1.1, and
the Java 2 platform; to replace the CGI sections with chapters on servlets 2.2 and JSP
1.1; and to add completely new sections on Swing, Java 2D, and XML processing
with JAXP, DOM Level 2, SAX 2.0, and XSLT. They even got a little bit of sleep along
the way.
We—Marty and Larry—hope you find the result enjoyable and useful!
This book is aimed at serious software developers. If you are looking for a book that
shows you how to use a browser, lists the current hottest Web sites, and pontificates
about how Web-enabled applications will revolutionize your business, you’ve come to
the wrong place. If you’re already a programmer of some sort and want to get started
with HTML, XML, Java applets, desktop applications in Java, servlets, JavaServer
Pages, and JavaScript as quickly as possible, this is the book for you. We illustrate the
most important approaches and warn you of the most common pitfalls. To do so, we
include plenty of working code: over 250 complete Java classes, for instance. We try
to give detailed examples of the most important and frequently used features, sum-
marize the lesser-used ones, and refer you to the API (available on-line) for a few of
the rarely used ones.
This book is divided into four parts: HTML, Java programming, server-side program-
ming, and JavaScript.
• HTML 4.01. Full coverage of all the elements in the latest official
HTML standard. Hypertext links, fonts, images, tables, client-side
image maps, and more.
• Major Netscape and Internet Explorer extensions. Forwarding
pages, using custom colors and font faces, embedding audio, video,
and ActiveX components.
xxxvi Introduction
• HTML forms. Sending data from forms. Text controls. Push buttons.
Check boxes and radio buttons. Combo boxes and list boxes. File
upload controls. Server-side image maps. Hidden fields. Tab ordering.
• Java servlets. The advantages of servlets over competing
technologies. Servlet life cycle. Servlet initialization parameters.
Accessing form data. Using HTTP 1.1 request headers, response
headers, and status codes. Using cookies in servlets. Session tracking.
• JavaServer Pages (JSP). The benefits of JSP. JSP expressions,
scriptlets, and declarations. Using JavaBeans components with JSP.
Creating custom JSP tag libraries. Combining servlets and JSP.
• Using applets as servlet front ends. Sending GET and POST data.
HTTP tunneling. Using object serialization to exchange high-level
data structures between applets and servlets. Bypassing the HTTP
server altogether.
• Java Database Connectivity (JDBC). The seven basic steps in
connecting to databases. Some utilities that simplify JDBC usage.
Formatting a database result as plain text or HTML. An interactive
graphical query viewer. Precompiled queries.
• XML processing with Java. Representing an entire XML document
by using the Document Object Model (DOM) Level 2. Responding to
individual XML parsing events with the Simple API for XML Parsing
(SAX) 2.0. Transforming XML with XSLT. Hiding vendor-specific
details with the Java API for XML Processing (JAXP).
Part 4: JavaScript
JavaScript is a scripting language that can be embedded in Web pages and
interpreted as the pages are loaded. The final part covers the following Java-
Script topics.
xxxviii Introduction
Conventions
Throughout the book, concrete programming constructs or program output is pre-
sented in a monospaced font. For example, when abstractly describing Java programs
that can be embedded in Web pages, we refer to “applets,” but when we refer to
Applet we are talking about the specific Java class from which all applets are
derived.
User input is indicated in boldface, and command-line prompts are either generic
(Prompt>) or indicate the operating system to which they apply (Unix>). For
instance, the following indicates that “Some Output” is the result when “java
SomeProgram” is executed.
Prompt> java SomeProgram
Some Output
Important standard techniques are indicated by specially marked entries, as in the
following example.
Core Approach
• Documented source code for all examples shown in the book; this
code can be downloaded for unrestricted use.
• On-line versions of all HTML pages, Java applets, and JavaScript
examples.
• Links to all URLs mentioned in the text of the book.
• Information on book discounts.
• Reports on Java short courses.
• Book additions, updates, and news.
• A free Ronco combination paring knife and e-commerce tool. OK,
maybe not.
Marty Hall is a Senior Computer Scientist in the Research and Technology Develop-
ment Center at the Johns Hopkins University Applied Physics Lab, where he special-
izes in the application of Java and Web technology to customer problems. He also
teaches Java and Web programming in the Johns Hopkins part-time graduate pro-
gram in Computer Science, where he directs the Distributed Computing and Web
Technology concentration areas. When he gets a chance, he also teaches industry
short courses on servlets, JavaServer Pages, and other Java technology areas. He is
the author of Core Servlets and JavaServer Pages and the first edition of Core Web
Programming. Marty can be reached at the following address:
Larry Brown is a Senior Network Engineer at the Naval Surface Warfare Center,
Carderock Division, where he specializes in developing and deploying network and
Web solutions in an enterprise environment. He is also a Computer Science faculty
member at the Johns Hopkins University, where he teaches server-side program-
xl Introduction
ming, distributed Web programming, and Java user interface development for the
part-time graduate program in Computer Science. Larry can be reached at the fol-
lowing address:
xli
This page intentionally left blank
1
THE HYPERTEXT
MARKUP LANGUAGE
Chapter 1 Designing Web Pages with HTML 4.0, 4
Chapter 2 Block-Level Elements in HTML 4.0, 28
Chapter 3 Text-Level Elements in HTML 4.0, 58
Chapter 4 Frames, 88
Chapter 5 Cascading Style Sheets, 114
Designing Web
Pages with
Chapter
HTML 4.0
• Use of the BODY tag to set up the basic look of the page
This page intentionally left blank
Chapter
1
T
his is the first of five chapters that cover the HyperText Markup Language
(HTML). Together, they teach you the techniques for creating professional
Web pages. This first chapter examines the underlying structure of an
HTML document, and the remaining four chapters cover additional topics for build-
ing quality Web pages, including block-level elements, text-level elements, frames,
and cascading style sheets. Once you’ve learned these basics, the remainder of Core
Web Programming covers advanced topics like Java applets, sockets, database con-
nectivity, Java servlets, JavaServer Pages (JSP), and processing XML. All of these
technologies are critical in developing quality Web sites.
The history of the HyperText Markup Language is briefly covered in this chapter,
followed by the steps necessary to create and publish a WWW page. We then focus
on the general structure of Web pages, describe which HTML elements are required
in all documents, and explain how to specify settings that affect the document as a
whole. In addition, we show you how to validate your Web page as legal HTML and
how to record information in your Web page for use by search engines.
5
6 Chapter 1 Designing Web Pages with HTML 4.0
ing) and leave many of the appearance and layout decisions to the browser. For
example, Listing 1.1 shows the HTML document used to create the Web page shown
in Figure 1–1. For now, don’t worry about the details of each of the HTML elements;
they are discussed in detail in the rest of Part 1 of this book. However, even at first
glance you can pick out some basic features, such as the mix of regular text and ele-
ments enclosed in angle brackets and that some but not all the elements come in
pairs of the form <NAME> and </NAME>.
The Web page shown in Figure 1–1 is the result for a particular browser (Internet
Explorer 5.0) on a particular operating system (Windows 2000 Professional) with the
browser and desktop preferences (font face, size, and color) set by the user. In addi-
tion to honoring user customizations, browsers usually have wide latitude in how they
implement the various types of elements, and authors who try to enforce an exact
appearance for pages that will be viewed by multiple browsers often end up frus-
trated. In Chapter 5 (Cascading Style Sheets), you will see a new standard that gives
authors a high degree of control over the final look of their pages. But even with style
sheets, authors of general Web pages should realize that they cannot control all
aspects of the final appearance of their page.
Figure 1–1 This page, rendered in Internet Explorer 5.0 on Windows 2000
Professional, is the result of the document in Listing 1.1.
Core Note
Trying to enforce an exact look for pages that will be viewed by people using
a variety of browsers will only lead to frustration.
The page design issue is further complicated because Web browsers are not the
only type of programs that use HTML documents. A variety of applications can display,
print, index, or even synthesize speech based on an HTML document. In this book,
however, we concentrate on how HTML documents are used by WWW browsers.
Along with browser issues, to a lesser degree, authors must also contend with
changes in the HTML specification. Until January 1997, HTML 2.0, introduced by
the World Wide Web Consortium (W3C), was the most up-to-date standard avail-
able. The HTML 2.0 specification describes the capabilities supported by most
Exploring the Variety of Random
Documents with Different Content
Shanghai dialect, °Zaung-°he °thoo-bak 上海土白.
A Buddhist priest, ih kuh oo-zaung° 一個和尙.
A Taoist priest, ih kuh dau°-z 一個道士.
A nun, ih kuh nyi-koo 一個尼姑.
Number, soo°-mak 數目.
EXERCISES
(一) 伊個賊常莊來偷物事捉着之末要綁伊起來.
(二) 我看見新聞紙上話官府已經出告示差兵丁去捉強盜.
(三) 儂那能佬撥伊打? 因爲我打勿過伊佬.
(四) 我拉廟裏看見多化和尙拉拜菩薩.
(五) 儂要學官話呢學上海土白.
(六) 和尚搭之道士是兩樣個和尙無沒頭髪道士有辮子個.
(七) 我常遠勿看新聞紙哉今朝有啥信息否?
(八) 第個一包貨色啥價錢?
(九) 伊個小囝幾歲哉? 六歲.
(十) 泥水匠已經買之一堆碌磚預備造房子.
(十一) 夜裏有月亮, 人歡喜吹笛.
(十二) 第個一包裏向有幾管筆? 有一百管.
(十三) 伊爲啥佬勿討娘子? 因爲現在討勿起佬.
(十四) 山上我看多化花有紅佬黃佬白實在可以話五顔六色個.
(十五) 外國人歡喜用鉛筆寫字.
(十六) 到上海勿滿念里路佬勿罷十二里路.
(十七) 因爲我看見伊個討飯個長遠勿吃啥蓋佬叫傭人撥點物事伊
吃.
(十八) 第個包要紥好拿到店裏去.
(十九) 老實告訴我是實蓋價錢否.
(二十) 四佬七佬八是啥個數目? 是十九.
(廿一) 尼姑是勿出嫁個小姐.
(1) If you do not read the newspaper, you will not know the
news, and then when you converse with others, you will
have nothing to say.
(2) When a man dies the Chinese invite Buddhist and Taoist
priests to the house to perform funeral ceremonies.
(3) I put my pen and pencil on my writing table, but now I
cannot find them; has any one been in and taken them?
(4) Which do you think is the pleasanter to listen to, mandarin
or the Shanghai dialect?
(5) When I was young I very much liked to play the flute.
(6) A thief enters secretly and steals things, a robber kills men
and enters and takes things by force.
(7) Chinese are called yellow men, foreigners white men.
(8) When you go to the shop, ask the price of the boots, and
come and tell me.
(9) I caught the thief and bound him to the tree.
(10) If you use a foreign pen to write Chinese characters, they
do not look well; you must learn to use a Chinese pen.
(11) The Chinese beggars in the city are numberless.
(12) When the Mandarin has important things to announce to
the people, he puts forth a proclamation.
(13) I saw more than a thousand soldiers.
(14) The merchant bought more than five hundred chests of
tea.
(15) Are three hundred dollars sufficient to buy the house? Less
than three hundred will do.
(一) 苦然儂勿看新聞紙信息儂勿會曉得難沒儂搭別人白話儂無啥
好話.
(二) 人死之末中國人請和尙佬道士到屋裏來念經.
(三) 我個筆佬鉛筆擺拉寫字檯上但是現在尋勿着, 有啥人進來拿
脫否?
(四) 儂想官話佬上海土白那裏一樣好聽點?
(五) 年紀輕個時候我蠻歡喜吹笛.
(六) 賊末偷伴之進來偷物事強盜末打殺之人佬進來搶物事.
(七) 中國人是叫黄人外國人是叫白人.
(八) 儂到店裏去問鞋子個價錢來告訴我.
(九) 我捉之伊個賊佬綁伊拉樹上.
(十) 若然用外國筆佬寫中國字是勿好看個儂終要學用中國筆.
(十一) 城裏個告化子無數目拉.
(十二) 官府有要緊個事體對百姓話末伊要出告示.
(十三) 我看見勿罷一千兵丁.
(十四) 生意人買之勿罷五百箱個茶葉.
(十五) 買房子三百塊洋錢有末? 勿消三百塊個.
Notes.
LESSON XXI
Verbal Idioms, Ordinals, and Remarks on the Expression of
Time
REMARKS ON TIME
EXERCISES
(一) 垃拉月半月亮頂好看.
(二) 火爐要隱快哉所以要加添煤.
(三) 照我看第個人是靠勿住個.
(四) 早晨頭日頭出來夜快落山
(五) 第個是我第二個兒子頭一個已經出門哉.
(六) 年初一多化人去拜年.
(七) 舊年米貴來死今年強哉.
(八) 儂那裏頭過年? 我想拉屋裏過年.
(九) 儂書讀之幾時哉? 必過半年.
(十) 年夜人人有事體新年裏攏總人勃相.
(十一) 伊將要去個時候有人來叫伊勿要去.
(十二) 請坐一歇先生要來快哉.
(十三) 天亮快是頂冾個時候.
(十四) 下個月我要出門到蘇州去.
(十五) 舊年生意一顔勿好今年把望伊好點.
(十六) 上半年第個學生子書讀來蠻好下半年一顔勿好.
(十七) 伊宅房子幾時可以造好? 我想開年可以造好.
(十八) 六月初三我寫一封信撥拉伊現在是七月初一但是還勿曾有
回信來.
(十九) 儂勿曾出去生活要先做好.
(二十) 月頭上撥銅錢現在勿好撥個.
(一)下個月初五伲要放學.
(二)放之幾個禮拜? 約酌六個禮拜.
(三)拉夜快日頭落山個時候常時拉天上有多化趣個顔色.
(四)照我看第本書儂六個月功夫可以讀完.
(五)我貼準要困個時候聽見人喊房子火着哉.
(六)賊進來是半夜把個時候.
(七)儂勿曾到學堂裏先要揩面佬淨手.
(八)拉年初一攏總個店全關門個.
(九)儂幾時再起頭讀中國書? 我想開年起頭.
(十)一年有十二個月一個月或者有三十日或者有念九日, 若然三
十日是叫大月若然念九日是叫小月.
(十一) 前個月我生病哉但是現在我好點.
(十二) 昨日下半日儂拉那裏頭? 我出去拜年哉.
(十三) 垃拉新年裏各人着頂好看個衣裳.
(十四) 現在無沒銅錢垃拉月底撥儂.
Notes.
LESSON XXII
On Comparison
VOCABULARY
°Kheu (口) is the classifier for some articles of furniture, and for a
well.
EXERCISES
(一) 拉年夜各人要算帳.
(二) 儂爲啥佬要去? 因爲伊差我去佬.
(三) 信寄出去末? 勿曾, 就要寄去.
(四) 石匠要用幾塊石頭? 我勿曉得勿曾算過歇.
(五) 伊常莊待我蠻好所以我要送點物事拉伊.
(六) 書橱裏儂擺之幾本書? 我勿曉得爲之勿曾數佬.
(七) 客人出去末應該送伊到門口.
(八) 第口棺材啥人做個? 木匠做個.
(九) 儂個馬比我個快多化.
(十) 第個學生子比之伊個聰明點.
(十一) 第個一對臘燭可以比比看一顔無末大小.
(十二) 伊個兩個人相駡個緣故是爲之拉酒店裏多吃之酒佬.
(十三) 現在付帳勿便當等到下個月.
(十四) 第個一對夫妻蠻好一顔勿相駡.
(十五) 笫個人做事體勿及伊個人好.
(十六) 拜年個時候小囝應該對大人磕頭.
(十七) 外國人吃飯個晨光歡喜吃饅頭.
(十八) 第個人一顔勿懂啥好像勿曾讀歇書.
(十九) 先生常莊叫學生子守規矩.
(二十) 勿要待慢別人.
(一) 中國人用米做酒.
(二) 第個人待伊個用人蠻好.
(三) 照中國規矩一個人勿曾死先要做棺材.
(四) 若然要儂來末我寄一封信來.
(五) 帶小囝去是勿便當.
(六) 伊比之儂年紀大點.
(七) 石匠用石頭木匠用木頭.
(八) 我個帳是拉月底付個.
(九) 因爲伊待慢我所以我對伊相駡.
(十) 我要木匠來做一口書橱.
(十一) 因爲我忘記脫之多化字所以好像我勿曾讀歇第本書.
(十二) 讀書人比之種田人聰明點.
(十三) 若然一個人多吃之酒伊勿會做生活.
(十四) 我個朋友來望望我後來我送伊到伊屋裏去.
(十五) 第本書我送撥儂勿要還個.
Notes.
(1) In the fifth sentence of the First Exercise notice the use of Soong° °tien.
°Tien means “a few things.”
(2) In the ninth sentence of the First Exercise kwha° too-hau° means “very
much faster.”
(3) In the sixteenth sentence of the First Exercise the expression Kheh-deu
refers to the most formal salute of the Chinese. It is used by an inferior
before a superior. The usual polite salutation is to clasp the hands
together and move them from the feet to the forehead. This is called
Tshaung° zo° (唱喏) or Tsauh-ih (作揖).
(4) In the nineteenth sentence of the First Exercise we have the expression
°Seu kwe-°kyui (守規矩). This is very frequently used. It means to act
according to the laws of propriety. It is a command frequently given to
children.
LESSON XXIII
The Points of the Compass
The four cardinal points of the compass in Chinese are expressed:
Toong, nen, si, pok (東, 南, 西, 北) East, South, West, North. Thus
it will be seen that they do not follow the same order as we. North
East is Toong-pok (東北), lit. East North. North West is Si-pok (西
北 ), lit. West North. South East is Toong-nen ( 東 南 ) , and South
West is Si-nen (西南).
The word pien (邊) is generally added when direction or place is
indicated. Thus we have for the North Pok-pien, for the West Si-
pien. Pien literally means “side,” and is a shortened form of pien-
deu (邊頭).
In giving directions as to locality, the Chinese make very frequent
use of the points of the compass.If you wish a person to go towards
the North you say dzau pok (朝北) “towards the North.”
VOCABULARY
(一) 中國竹頭大有用頭可以做籃佬檯子佬椅子佬多化物事.
(二) 我問之伊三回但是伊一句勿回頭.
(三) 種田人養多化雞佬鴨.
(四) 好拉否? 好拉謝謝.
(五) 今朝好點否? 昨夜頭吃之藥佬今朝稍爲好點.
(六) 日頭東邊出佬西邊落.
(七) 北邊冷佬南邊煖.
(八) 我伲要大家商量那能做頭.
(九) 第個玻璃蠻薄個容易打碎.
(十) 看見人要做勿好個事體末應該阻擋伊.
(十一) 看羊人失脫之一隻羊佬要去尋伊.
(十二) 先生要幾化束脩? 要三十塊洋錢一月.
(十三) 儂個用人幾化工錢一月? 六塊洋錢一月.
(十四) 東北風要落雨.
(十五) 現在拉落雨終要擔一頂傘省之淋濕.
(十六) 昨日我走之三十里路所以今朝我蠻弛瘏.
(十七) 我點擦伊看一條蛇.
(十八) 第個官府勿會辦事體.
(十九) 儂倒來哉我貼準要到儂壗頭去.
(二十) 第個人失脫之伊個生意佬生之長遠個病實在苦惱得極.
(廿一) 第隻箱子是方個第隻桶是圓個.
(廿二) 出店來話要銅錢爲之要去買一把掃帚佬.
(廿三) 第個紙頭忒薄要儂去換厚點個.
(廿四) 儂忒弛瘏我來代儂做.
(廿五) 第扇門勿好開去叫木匠弄好.
(廿六) 伊個說話搭之儂個說話有分別.
(廿七) 第個兩個人常莊相駡分開末好.
(1) Is there any answer? Yes, please wait until I write it.
(2) The cold wind blows from the North; you ought to wear
more clothes.
(3) The scholar was unable to answer what the teacher asked
him.
(4) I want to consult with you on an important matter.
(5) When it rains the children cannot go out to play.
(6) I have a fan, you have a knife, I want a knife, you want a
fan, let us exchange.
(7) I killed the snake with a stick.
(8) Tell the compradore what you want to buy and he can buy it
for you.
(9) I have lost my watch and am willing to give five dollars to
the man who finds it and returns it to me.
(10) My salary is not sufficient; I must ask you to increase it.
(11) This coolie wipes and sweeps very clean.
(12) I pointed out the river to him on the map.
(13) I cannot go away until I have arranged this matter.
(14) I could not study diligently to-day because I was too tired.
(15) How many bottles of medicine have you taken? I have
already finished three.
Notes.
(1) Those learning to speak Chinese must be careful never to refer to the
remuneration given to their teachers as koong-dien (工錢), but to use
the polite form of speech, sok-sieu or sing-foong (束脩, 薪俸). Sok-sieu
means literally “dried meat,” and comes from the ancient custom of
paying a teacher in kind. The teacher himself could refer to
remuneration as sing° soe (薪水).
(2) °Eu (厚) and Bok (薄) refer to things. In speaking of a person being thin
we use the word seu° (瘦), and of being fat, the word tsaung° 壯.
(3) The fourth sentence of the First Exercise is the usual salutation meaning,
“How do you do?” “Does it go well with you?” The answer is also the
usual one.
(4) In the ninth sentence of the Second Exercise Zing nyoen° (情願) means
“to be willing.”
(5) In the seventh sentence of the First Exercise °Noen means “warm” (煖).
(6) In the eleventh sentence of the First Exercise Koen°-yang-nyung means
“shepherd.” Literally “Look-sheep-man.”
(7) In the twenty-fifth sentence of the First Exercise the word Loong has a
very wide meaning. There is hardly anything in China that you cannot
Loong-°hau, that is, “put to rights.”
LESSON XXIV
Some Remarks on Gender
VOCABULARY
To crow, di 啼.
To offend, tuh-°dzoe 得罪.
To hide oneself, ben°-°loong 背攏.
To hide a thing, khaung°-°loong 囥攏, or khaung° 囥.
To gain or make a profit, dzan° 賺.
Profits in business, dzan°-deu 賺頭.
To lose in business, zeh 折, zeh-theh 折脫, zeh-°pung 折本.
To congratulate a person, koong-°hyi 恭喜.
To become rich, fah-dze 發財.
To lock, °soo 鎖.
To bar or bolt the door, sen 閂.
The bar, or bolt of the door, sak 栅.
To plant, tsoong° 種.
To examine carefully, dzo 查, or dzo-°khau 查考.
To examine a class, °khau-su 考書.
To fall, tih 跌.
To save, kyeu° 救.
To stop, ding 停.
Stop a minute, ding-ih-ding 停一停.
Garden, hwo-yoen 花園.
College, su-yoen° 書院.
University, da°-‘auh 大學.
A lock, ih °po °soo 一把鑕.
A key, ih °po yak-dz 一把鑰匙.
A creek or canal, ih diau pang 一條浜.
A two story house, ih zoo° leu 一座樓, or leu-vaung 褸房.
EXERCISES
(一) 地上滑佬當心點走.
(二) 四季叫春夏秋冬.
(三) 我碰着之一個人佬要伊讓路, 所以對伊話得罪得罪, 伊話勿要
客氣.
(四) 儂做第個生意一年要賺幾化? 無啥賺頭倒折本.
(五) 年初一碰着之人照規矩應該對伊話恭喜發財.
(六) 人做惡個事體是拉暗裏做個.
(七) 爲之怕別人要查着佬, 伊個人去背攏.
(八) 夜裏終要鎖門, 恐怕賊進來偷物事.
(九) 中國門用栅來閂個, 外國門用鑰匙來鎖個.
(十) 小囝拉勃相個時候跌拉浜裏, 快點去救伊.
(十一) 雄窵會叫, 雌窵勿會叫.
(十二) 雌獅子比之雄獅子更加凶.
(十三) 第個人有三個男囝佬一個女囝, 實在有福氣.
(十四) 第個物事是寶貝個, 要囥好.
(十五) 下禮拜, 書院裏要考書.
(十六) 第個一埭房子高來死, 攏總是四層樓.
(十七) 第條路勿平, 煩難走個.
(十八) 淸水好吃個, 渾水勿好吃.
(十九) 石頭是硬個, 饅頭是軟個.
(二十) 到底末善人一定要得着福氣.
(一) 拉花園裏種花園個種三埭蘋菓樹.
(二) 早晨頭雞啼個以後我勿能再睏.
(三) 第個人是蠻客氣所以攏總人歡喜伊.
(四) 冬天個時候我伲關攏總個門佬窗佬生火夏天個時候我伲開攏
總個門佬窗.
(五) 浜裏水是渾佬勿好吃個.
(六) 有人做生意是發財有人末折本.
(七) 鎖門佬勿要讓貓進來.
(八) 小囝從椅子上跌下來所以拉哭.
(九) 昨日我去看七層樓個塔.
(十) 第個帳勿對個算來勿淸爽.
(十一) 我查勿出第個人做啥惡事.
(十二) 我碰着之強盜我喊人來救命.
(十三) 第個人凶來死所以常莊相打.
(十四) 拉年底書院裏攏總個學生子要考書.
(十五) 我失脫之我個鑰匙佬勿好開我個箱子.
(十六) 我想儂勿曾失脫恐怕儂已經囥好佬忘記擺拉啥地方, 讓我
去尋尋看.
Notes.
LESSON XXV
Weights and Measures
The following three Tables are very commonly used in China, and
the speaker of the language should be familiar with them.
MEASURE OF WEIGHT
MEASURE OF DISTANCE
CURRENCY
Until recently, aside from copper cash, the Chinese had no regular
system of currency. An ounce of silver was taken as a standard. The
following Table is based upon that:—
VOCABULARY