Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

Murach s Java Servlets and JSP 3rd

Edition Murach Training Reference Joel


Murach Michael Urban
Visit to download the full and correct content document:
https://textbookfull.com/product/murach-s-java-servlets-and-jsp-3rd-edition-murach-tr
aining-reference-joel-murach-michael-urban/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Murach s Java Programming Joel Murach

https://textbookfull.com/product/murach-s-java-programming-joel-
murach/

Murach s Mysql 3rd Edition Joel Murach

https://textbookfull.com/product/murach-s-mysql-3rd-edition-joel-
murach/

Murach s SQL Server 2019 for Developers 1st Edition


Joel Murach

https://textbookfull.com/product/murach-s-sql-server-2019-for-
developers-1st-edition-joel-murach/

Murach s HTML5 and CSS3 Anne Boehm

https://textbookfull.com/product/murach-s-html5-and-css3-anne-
boehm/
Java EE Web Application Primer: Building Bullhorn: A
Messaging App with JSP, Servlets, JavaScript, Bootstrap
and Oracle 1st Edition Dave Wolf

https://textbookfull.com/product/java-ee-web-application-primer-
building-bullhorn-a-messaging-app-with-jsp-servlets-javascript-
bootstrap-and-oracle-1st-edition-dave-wolf/

Beginning JSP JSF and Tomcat Java Web Development


Expert s Voice in Java 2 New Edition Zambon Giulio

https://textbookfull.com/product/beginning-jsp-jsf-and-tomcat-
java-web-development-expert-s-voice-in-java-2-new-edition-zambon-
giulio/

Java quick syntax reference Second Edition Olsson

https://textbookfull.com/product/java-quick-syntax-reference-
second-edition-olsson/

FACILITIES MANAGER S DESK REFERENCE 3rd Edition Jane M.


Wiggins

https://textbookfull.com/product/facilities-manager-s-desk-
reference-3rd-edition-jane-m-wiggins/

Java: The Complete Reference, Eleventh Edition Herbert


Schildt

https://textbookfull.com/product/java-the-complete-reference-
eleventh-edition-herbert-schildt/
I

3RD EDITION
TRAINING & REFERENCE

3RD EDITION

Joel Murach
Michael Urban

MIKE MURACH & ASSOCIATES, INC.


4340 N. Knoll Ave. • Fresno, CA 93722
www.murach.com • murachbooks@murach.com
Authors: Joel Murach
Michael Urban
Editor: Ray Halliday
Production: Maria Spera

Books for Java programmers


Murach's Java Programming
Murach's Android Programming
Murach's Java Servlets and ISP (Jrd Edition)

Books for web developers


Murach's HTML5 and CSS3
Murach's Dreamweaver CC
Murach's JavaScript andjQuery
Murach's JavaScript and DOM Scripting
Murach's PHP and MySQL

Books for .NET programmers


Murach's C# 2012
Murach's ASP.NET 4.5 Web Programming with C# 2012
Murach's Visual Basic 2012
Murach's ASP.NET 4.5 Web Programming with VB 2012

Books for database developers


Murach's MySQL
Murach's Oracle SQL and PL!SQL
Murach's SQL Server 2012 for Developers

Books for IBM mainframe programmers


Murach's OS/390 and z/OS JCL
Murach's Mainframe COBOL
Murach's CfCS for the COBOL Programmer

Please check www.murach.com


for the most up-to-date Murach books

© 2014, Mike Murach & Associates, Inc.


All rights reserved.
Printed in the United States of America

10 9 8 7 6 5 4 3 2 1
ISBN-13: 978-1-890774-78-3
Content
Introduction

Section 1 Get started right


Chapter 1 An introduction to web programming with Java 3
Chapter 2 How to structure a web application with the MVC pattern 29
Chapter 3 How to use NetBeans and Tomcat 49

Section 2 Essential servlet and JSP skills


Chapter 4 A crash course in HTML5 and CSS3 89
Chapter 5 How to develop serv lets 127
Chapter 6 How to develop JavaServer Pages 173
Chapter 7 How to work with sessions and cookies 201
Chapter 8 How to use EL 243
Chapter 9 How to use JSTL 269
Chapter 10 How to use custom JSP tags 307

Section 3 Essential database skills


Chapter 11 How to use a MySQL database 347
Chapter 12 How to use JDBC to work with a database 377
Chapter 13 How to use JPA to work with a database 421

Section 4 Advanced servlet and JSP skills


Chapter 14 How to use JavaMail to send email 459
Chapter 15 How to use SSL to work with a secure connection 483
Chapter 16 How to restrict access to a web resource 501
Chapter 17 More security skills 525
Chapter 18 How to work with HTTP requests and responses 543
Chapter 19 How to work with listeners 571
Chapter 20 How to work with filters 587
Chapter 21 How to work with JavaServer Faces 613

Section 5 The Music Store website


Chapter 22 An introduction to the Music Store website 643
Chapter 23 The applications of the website 673

Appendixes
Appendix A How to set up your PC for this book 691
Appendix B How to set up your Mac for this book 711
••
Expanded contents VI I

Expanded contents
Section 1 Get started right
Chapter 1 An introduction to web applications
A typical web application ............................................................................................... 4
The components of a web application ............................................................................ 6
How static web pages work .............................................................................................8
How dynamic web pages work ..................................................................................... 10
Three approaches for Java web applications ................................ 12
Servlet/JSP .................................................................................................................... 12
JSF ................................................................................................................................. 12
Spring Framework ........................................................................................................ 12
An introduction to servlet/JSP web development ........................ 14
The software components ............................................................................................. 14
The architecture ............................................................................................................ 16
The standard directories and files ................................................................................. 18
Software for developing Java web applications ............................20
IDEs for developing Java web applications .................................................................. 20
Web servers for Java web applications ......................................................................... 22
Database servers for Java web applications .................................................................. 22
Tools for deploying Java web applications ................................................................... 24

Chapter 2 How to structure a web application


with the MVC patt'ern
Two patterns for servlet/JSP applications ..................................... 30
The Model 1 pattern ...................................................................................................... 30
The Model 2 (MVC) pattern ......................................................................................... 32
A servlet/JSP application that uses the MVC pattern ................... 34
The user interface ......................................................................................................... 34
The HTML for the first page ........................................................................................ 36
The CSS for both web pages ......................................................................................... 38
The servlet for the back-end processing ....................................................................... 40
The web.xml file ........................................................................................................... 42
The User class ............................................................................................................... 44
The JSP for the second page .........................................................................................46

Chapter 3 How to use NetBeans and Tomcat


How to get started with NetBeans .................................................. 50
How to start NetBeans .................................................................................................. 50
How to create a new web application ........................................................................... 52
How to use the Projects window ................................................................................... 56
How to open and close projects .................................................................................... 58
How to build , deploy, and run a web application ......................................................... 60
How to work with HTML and JSP files ............................................ 62
How to add an HTML or JSP' file ................................................................................. 62
How to edit an HTML or JSP file .................................................................................64
•••
VI 11 Expanded contents

How to work with Java files ............................................................. 66


How to add a Java class ................................................................................................. 66
How to add a servlet...................................................................................................... 68
How to edit a Java file ................................................................................................... 70
How to work with XML files .............................................................. 72
How to edit the web.xml file......................................................................................... 72
How to edit other XML files ......................................................................................... 72
Other skills for working with web applications ............................. 74
How to add existing files to a project............................................................................ 74
How to deploy a web application to a remote server .................................................... 74
How to work with a web application server .................................................................. 76
How to add a class library or a JAR file to a project .................................................... 78
How to register a database connection ......................................................................... 80

Section 2 Essential servlet and JSP skills


Chapter 4 A crash course in HTMLS and CSS3
How to work with HTML ................................................................... 90
The starting HTML for a web page.............................................................................. 90
How to code HTML elements ...................................................................................... 92
How to use the HTML5 semantic elements ................................................................. 94
How to use the div and span elements with HTML5 ................................................... 96
How to ensure cross-browser compatibility ................................................................. 98
How to code links ....................................................................................................... 100
How to include images ................................................................................................ 102
How to code tables ...................................................................................................... 104
How to work with CSS .................................................................... 106
How to provideCSS styles for an HTML page .......................................................... 106
How to code the basic CSS selectors .......................................................................... 108
How to codeCSS rule sets and com ments ................................................................. 110
How to useCSS to format a table ............................................................................... 112
How to code HTML forms ............................................................... 114
How to code a form ..................................................................................................... 114
How to code text boxes ............................................................................................... 116
How to code buttons ................................................................................................... 118
How to code check boxes and radio buttons............................................................... 120
How to code combo boxes and list boxes ................................................................... 122

Chapter 5 How to develop servlets


How to create and map a servlet ................................................... 128
How to create a servlet ................................................................................................ 128
How to map a servlet with the web.xml file ............................................................... 130
How to map a servlet with an annotation ................................................................... 132
How to request a servlet ................................................................ 134
How to use the HTTP GET method ........................................................................... 134
How to use the HTTP POST method ......................................................................... 136
When to use the HTTP GET and POST methods ...................................................... 136
Skills for working with servlets ..................................................... 138
How to get the values of the parameters..................................................................... 138
How to get the real path for a file ............................................................................... 140
Expanded contents IX

How to get and set request attributes .......................................................................... 142


How to forward requests ............................................................................................. 144
How to redirect responses........................................................................................... 144
How to validate data ....................................................................... 146
How to validate data on the client .............................................................................. 146
How to validate data on the server ............................................................................. 146
How to work with the web.xml file ................................................. 150
A complete web.xml file ............................................................................................. 150
How to work with initialization parameters ............................................................... 152
How to implement custom error handling .................................................................. 156
More skills for working with servlets ............................................ 160
How the methods of a servlet work ............................................................................ 160
Why you shouldn't use instance variables in servlets ................................................ 162
How to work with servlet errors .................................................... 164
How to solve common servlet problems ..................................................................... 164
How to print debugging data to the console ............................................................... 166
How to print debugging data to a log file ................................................................... 168

Chapter 6 How to develop JavaServer Pages


A crash course in EL and JSTL ..................................................... 174
How to code a JavaBean ............................................................................................. 174
How to use EL to get attributes and JavaBean properties .......................................... 176
How to enable the core JSTL library .......................................................................... 178
How to use the JSTL if tag ......................................................................................... 178
How to use JSP tags ....................................................................... 180
How to code directives, scriptlets, and expressions ................................................... 180
How to code comments in a JSP ................................................................................. 182
How to use standard JSP tags with Java Beans .......................... 184
An introduction to standard JSP tags ......................................................................... 184
How to code the useBean tag ...................................................................................... 186
How to code the getProperty and setProperty tags .................................................... 188
How to include a file in a JSP ........................................................ 190
A JSP that includes a header and footer file ............................................................... 190
Three techniques for including files in a JSP ............................................................. 194
How to fix common JSP errors...................................................... 196
Chapter 7 How to work with sessions and cookies
An introduction to session tracking .............................................202
Why session tracking is difficult with HTTP ............................................................. 202
How session tracking works in Java ...........................................................................202
An application that needs session tracking.................................................................204
How to work with sessions ............................................................206
How to set and get session attributes .......................................................................... 206
More methods of the session object. ........................................................................... 208
How to provide thread-safe access to the session object............................................ 210
How to work with cookies .............................................................. 212
An introduction to cookies ......................................................................................... 212
How to create and use cookies.................................................................................... 214
How to view and delete cookies ................................................................................. 216
X Expanded contents

Four methods for working with cookies ..................................................................... 218


A utility class for working with cookies ..................................................................... 220
How to work with URL rewriting and hidden fields ..................... 222
How to use URL rewriting to pass parameters .......................................................... 222
How to use hidden fields to pass parameters .............................................................. 224
The Download application ............................................................. 226
The user interface ....................................................................................................... 226
The file structure ......................................................................................................... 228
The web.xml file ......................................................................................................... 228
The code for the JSPs .................................................................................................. 230
The code for the servlet .............................................................................................. 234

Chapter 8 How to use EL


An introduction to JSP Expression Language ............................ 244
Advantages of EL........................................................................................................244
Disadvantages of EL ...................................................................................................244
Essential skills for working with EL.............................................. 246
How to use the dot operator to work with JavaBeans and maps ................................246
How to use EL to specify scope ................................................................................. 248
How to use the [ ] operator to work with arrays and lists ........................................... 250
How to use the dot operator to access nested properties ............................................ 252
Other skills for working with EL .................................................... 254
How to use the [ ] operator to access attributes .......................................................... 254
How to work with the other implicit EL objects ........................................................ 256
How to work with other EL operators ........................................................................ 260
How to disable EL....................................................................................................... 264
How to disable scripting ............................................................................................. 264

Chapter 9 How to use JSTL


An introduction to JSTL ................................................................. 270
The JSTL libraries ...................................................................................................... 270
How to make the JSTL JAR files available to your application ................................. 270
How to code the taglib directive ................................................................................. 270
How to code a JSTL tag .............................................................................................. 270
How to view the documentation for a library ............................................................. 272
How to work with the JSTL core library ....................................... 274
How to use the out tag ................................................................................................. 274
How to use the for Each tag ......................................................................................... 276
How to use the forTokens tag ...................................................................................... 278
Four more attributes for looping ................................................................................. 280
How to use the if tag ................................................................................................... 282
How to use the choose tag .......................................................................................... 284
How to use the url tag ................................................................................................. 286
Other tags in the JSTL core library ............................................................................ 288
The Cart application ....................................................................... 290
The user interface ....................................................................................................... 290
The code for the business classes ............................................................................... 292
The code for the servlets and JSPs .............................................................................. 296
Expanded contents XI

Chapter 10 How to use custom JSP tags


How to code a custom tag that doesn't have a body .................. 308
The tag ........................................................................................................................ 308
The tag element ........................................................................................................... 310
The tag class................................................................................................................ 312
How to code a custom tag that has a body .................................. 314
The tag ........................................................................................................................ 314
The tag element ........................................................................................................... 316
The tag class................................................................................................................ 316
How to code a custom tag that has attributes ............................. 318
The tag ........................................................................................................................ 318
The tag element ........................................................................................................... 320
The tag class................................................................................................................ 322
How to code a custom tag that reiterates its body ..................... 324
The tag ........................................................................................................................ 324
The tag element ........................................................................................................... 326
The tag class................................................................................................................ 326
How to work with scripting variables............................................330
An introduction to scripting variables ........................................................................ 330
The TEI class for four scripting variables .................................................................. 332
Classes, methods, and fields for working with custom tags ..... 334
Methods and fields of the Tag Support class ............................................................... 334
Methods and fields of the PageContext class.............................................................. 336
Methods and fields of the BodyTagSupport class ....................................................... 338
Methods and fields of the BodyContent class............................................................. 340

Section 3 Essential database skills


Chapter 11 How to use a MySQL database
An introduction to MySQL .............................................................348
What MySQL provides ............................................................................................... 348
Two ways to interact with MySQL ............................................................................. 350
How to use MySQL Workbench ..................................................... 352
The Home tab of MySQL Workbench ........................................................................ 352
How to open a database connection............................................................................ 354
How to start and stop the MySQL ser ver ................................................................... 356
How to enter and execute a SQL statement ................................................................ 358
How to enter and execute a SQL script....................................................................... 360
The SQL statements for creating a database ..............................362
How to create, select, and drop a database ................................................................. 362
How to create and drop a table ................................................................................... 364
How to insert multiple rows into a table ..................................................................... 366
The SQL statements for data manipulation ................................. 368
How to select data from a single table ........................................................................ 368
How to select data from multiple tables ..................................................................... 370
How to insert, update, and delete data........................................................................ 372
••
XI I Expanded contents

Chapter 12 How to use JDBC to work with a database


How to work with JDBC .................................................................. 378
An introduction to database drivers ............................................................................ 378
How to connect to a database ..................................................................................... 380
How to return a result set and move the cursor through it ......................................... 382
How to retrieve data from a result set. ........................................................................ 384
How to insert, update, and delete data ........................................................................ 386
How to work with prepared statements ...................................................................... 388
The SQL Gateway application .......................................................390
The user interface ....................................................................................................... 390
The code for the JSP ................................................................................................... 392
The code for the servlet .............................................................................................. 394
The code for the utility class ....................................................................................... 398
How to work with connection pooling .......................................... 400
How connection pooling works .................................................................................. 400
How to make a connection pool available .................................................................. 400
How to implement a connection pool .........................................................................402
How to use a connection pool .....................................................................................404
The Email List application .............................................................406
The user interface .......................................................................................................406
The code for the JSP ...................................................................................................406
The code for the servlet .............................................................................................. 408
The code for the database class .................................................................................. 410
The code for the utility class ....................................................................................... 416

Chapter 13 How to use JPA to work with a database


An introduction to JPA ................................................................... 422
A summary of JPA implementations .......................................................................... 422
Entities and the entity manager .................................................................................. 422
How to configure NetBeans to work with JPA ........................................................... 424
How to configure a persistence unit. ........................................................................... 426
How to code JPA entities ............................................................... 428
How to code the class for an entity .. ........................................................................... 428
How to use getter and field annotations ...................................................................... 430
How to code relationships between entities ................................................................ 432
How to work with dates and times .............................................................................. 434
How to retrieve data........................................................................ 436
How to get an entity manager factory ......................................................................... 436
How to retrieve an entity by primary key ................................................................... 438
How to retrieve multiple entities ................................................................................. 440
How to retrieve a single entity .................................................................................... 442
How to modify data ......................................................................... 444
How to insert, update, or delete a single entity ..........................................................444
How to update or delete multiple entities ...................................................................446
A complete JPA class.....................................................................448
The methods that modify data ....................................................................................448
The methods that retrieve data ................................................................................... 450
•••
Expanded contents XIII

Section 4 Advanced servlet and JSP skills


Chapter 14 How to use JavaMail to send mail
An introduction to the JavaMail API ............................................. 460
How email works ........................................................................................................460
How to install the JavaMail APL................................................................................ 462
Code that uses the JavaMail API to send an email message ...................................... 464
How to create and send an email message ................................. 466
How to create a mail session ....................................................................................... 466
How to create a message ............................................................................................. 468
How to address a message .......................................................................................... 470
How to send a message ............................................................................................... 472
Example classes that send an email message ............................ 474
A helper class for sending an email with a local SMTP server.................................. 474
A servlet that uses a helper class to send an email message ...................................... 476
A helper class for sending an email with a remote SMTP server .............................. 480

Chapter 15 How to use SSL to work with a secure connection


An introduction to SSL ................................................................... 484
How SSL works........................................................................................................... 484
How TLS works .......................................................................................................... 484
When to use a secure connection................................................................................ 484
How SSL authentication works................................................................................... 486
How to get a digital secure certificate ........................................................................ 488
How to configure a testing environment for SSL ........................ 490
How to create a certificate for testing ......................................................................... 490
How to enable SSL in Tomcat..................................................................................... 492
How to test a local SSL connection ............................................................................ 492
How to work with a secure connection ........................................ 494
How to request a secure connection ........................................................................... 494
A JSP that uses a secure connection ........................................................................... 496
How to return to a regular HTTP connection ............................................................ 496
How to switch from a local system to an Internet server ........................................... 496

Chapter 16 How to restrict access to a web resource


An introduction to authentication ................................................. 502
How container-managed authentication works........................................................... 502
T hree types of authentication ..................................................................................... 504
How to restrict access to web resources ..................................... 506
How to add a security role .......................................................................................... 506
How to add a security constraint ................................................................................ 506
How to implement a security realm .............................................. 508
How to implement the UserDatabaseRealm ............................................................... 508
How to implement the JDBCRealm ........................................................................... 510
How to implement the DataSourceRealm .................................................................. 514
How to allow access to authorized users ..................................... 516
How to use basic authentication.................................................................................. 516
How to use digest authentication ................................................................................ 516
How to use form-based authentication ....................................................................... 518
XIV Expanded contents

Chapter 17 More security skills


An introduction to website security.............................................. 526
Common website attacks ............................................................................................ 526
How to prevent social engineering attacks ................................................................. 526
An introduction to cryptography ................................................................................ 528
Common password attacks ......................................................................................... 530
How to protect passwords ............................................................. 532
How to hash passwords ............................................................................................... 532
How to salt passwords ................................................................................................. 534
A utility class for hashing and salting passwords ....................................................... 536
How to enforce password strength requirements ....................................................... 538

Chapter 18 How to work with HTTP requests and responses


An introduction to HTTP ................................................................ 544
An HTTP request and response .................................................................................. 544
Common MIME types ................................................................................................ 546
Common HTTP request headers ................................................................................ 548
Common HTTP status codes ...................................................................................... 550
Common HTTP response headers .............................................................................. 552
How to work with the request ........................................................ 554
How to get a request header ........................................................................................ 554
How to display all request headers ............................................................................. 556
How to work with the response ..................................................... 558
How to set status codes ............................................................................................... 558
How to set response headers ....................................................................................... 558
Practical HTTP skills ...................................................................... 560
How to return a spreadsheet ....................................................................................... 560
How to control caching ............................................................................................... 560
How to compress a response with GZIP..................................................................... 562
How to return a binary file as an attachment ............................................................. 564
How to create virtual HTML pages............................................................................ 566

Chapter 19 How to work with listeners


How to use a ServletContextlistener ........................................... 572
How to code a class for the listener ............................................................................ 572
How to register the listener ......................................................................................... 574
How to code a JSP that uses the attributes set by the listener .................................... 576
How to work with other types of listeners.................................... 578
A summary of the listener interfaces ......................................................................... 578
The methods of the listener interfaces ........................................................................ 580
The methods of the event objects ............................................................................... 582

Chapter 20 How to work with fliters


An introduction to filters ................................................................ 588
How filters work .......................................................................................................... 588
Two benefits of filters .................................................................................................. 588
When to use filters ...................................................................................................... 588
How to add a filter ........................................................................... 590
How to code a filter ..................................................................................................... 590
How to configure a filter ............................................................................................. 592
Expanded contents XV

Two filter classes ............................................................................ 596


How to code a filter that performs request-side processing ....................................... 596
How to code a filter that performs response-side processing ..................................... 598
Other skills for workin,g with filters............................................... 600
How to wrap a request or response ............................................................................. 600
How to use an initialization parameter ....................................................................... 604
How to restrict access by IP address .......................................................................... 606

Chapter 21 How to work with JavaServer Faces


An introduction to JSF ................................................................... 614
A summary of JSF versions ........................................................................................ 614
How to add a JSF library to a project ......................................................................... 614
How to used managed beans ........................................................ 616
How to create a managed bean ................................................................................... 616
How to set the scope of a bean ................................................................................... 618
How to use standard JSF tags ...................................................... 620
How to code the head and body tags .......................................................................... 620
How to display data from a managed bean................................................................. 622
How to code the inputText tag .................................................................................... 624
How to validate data ................................................................................................... 626
How to code a form action .......................................................................................... 628
The Email List application ............................................................. 630
The user interface ....................................................................................................... 630
The EmailList bean..................................................................................................... 632
The index.xhtml file .................................................................................................... 634
The thanks.xhtml file .................................................................................................. 636

Section 5 The Music Store website


Chapter 22 An introduction to the Music Store website
The user interface ........................................................................... 644
The Home and Catalog pages ..................................................................................... 644
The code for the Home page ....................................................................................... 644
The business layer .......................................................................... 648
The class diagrams ...................................................................................................... 648
The Product class ........................................................................................................ 648
The controller layer......................................................................... 652
The CatalogController class ....................................................................................... 652
The structure ................................................................................... 656
The directory structure ............................................................................................... 656
The web.xml file ......................................................................................................... 658
The context.xml file .................................................................................................... 658
The database ................................................................................... 662
The database diagram ................................................................................................. 662
The SQL script for the database ................................................................................. 662
The data layer .................................................................................. 666
The class diagrams...................................................................................................... 666
The ProductDB class .................................................................................................. 666
XVI Expanded contents

The JPA version compared to the JDBC version ........................ 670


The similarities ........................................................................................................... 670
The differences ........................................................................................................... 670

Chapter 23 The applications of the website


The user interface for end users ................................................... 674
The Download application.......................................................................................... 674
The Cart application ................................................................................................... 674
The user interface for administrators ........................................... 680
The Ad min Login page ............................................................................................... 680
The Ad min Menu page ............................................................................................... 682
The Process Invoices application................................................................................ 684
The Reports application .............................................................................................. 684

Appendix A How to set up your PC for this book


How to install the source code for this book .............................................................. 692
How to install the JDK ............................................................................................... 694
How to install NetBeans ............................................................................................. 696
How to install Tomcat ................................................................................................. 698
How to configure a Tomcat server .............................................................................. 700
How to test NetBeans and Tomcat .............................................................................. 704
How to install MySQL ................................................................................................ 706
How to create the databases for this book .................................................................. 708
How to restore the databases for this book................................................................. 708

Appendix B How to set up your Mac for this book


How to install the source code for this book .............................................................. 712
How to install the JDK ............................................................................................... 714
How to install NetBeans ............................................................................................. 716
How to install Tomcat ................................................................................................. 718
How to configure a Tomcat server .............................................................................. 720
How to test NetBeans and Tomcat .............................................................................. 724
How to install the MySQL Community Server .......................................................... 726
How to install MySQL Workbench ............................................................................ 728
How to create the databases for this book .................................................................. 730
How to restore the databases for this book................................................................. 730
How to update the password for the root user ............................................................ 732
Introduction
Java servlets and JavaServer Pages (JSPs) came into widespread use in the
late 1990s. For many years, servlets and JSPs were the dominant technology for
building web applications, especially for large enterprises. Although servlets and
JSPs are no longer the dominant approach to web programming, they have some
advantages over other newer approaches. In addition, since there are still many
legacy web applications powered by them, servlets and JSPs will continue to be
relevant for many years to come.
A quick search on a typical job website shows that there is still plenty
of demand for servlet and JSP developers. In addition, many of the skills for
working with servlets and JSPs also apply to newer approaches to Java web
development such as JavaServer Faces (JSF). As a result, learning servlets and
JSPs is still a great way to get started with Java web programming.

Who this book is for


This book is for anyone who wants to learn how to develop web applications
using servlets and JSP. The only prerequisite is a basic understanding of the Java
programming language roughly equivalent to chapters 1 through 14 of our core
Java book, Murach's Java Programming. Once you have the necessary Java
skills, this book should work for you even if you have no experience developing
web applications.

Why you'll learn faster and better with this book


When we started writing this book, we knew we had to take a new approach
if we wanted to teach you everything you need to know in a way that's faster and
better than the other books. Here, then, are a few of the ways in which our book
differs from the others:
• Chapter 2 shows how to use the MVC pattern (or Model 2 architecture) to
get the most from JSPs and servlets. This allows you to use servlets when
they're appropriate and JSPs when they're appropriate. As a result, you
won't waste your time learning how to use servlets for tasks that should be
handled by JSPs, or vice versa.
•••
XVI 11 Introduction

• Chapter 3 shows how to use the NetBeans IDE with a Tomcat server to
develop web applications on your own computer. By using this IDE, you'll
learn faster and better than you would without one. In contrast, most
competing books leave you to figure this out on your own.
• Chapter 4 of this book provides a crash course in HTML5 and CSS3. Since
this is essential background for the use of JSPs, this means you won't have
to use a second book to figure out how HTML and CSS work.
• This book includes dozens of examples that range from the simple to
the complex. That way, you can quickly see how a feature works from
the simple examples, but you'll also see how the feature is used in more
complex, real-world examples, including the complete e-commerce
application that's presented in section 5.
• At the end of most chapters, you'll find exercises that help you practice what
you've learned. They also encourage you to experiment and challenge you to
apply what you've learned in new ways. To help you get the most practice in
the least time, you'll start these exercises from existing applications.
• If you page through this book, you'll see that all of the information is
presented in "paired pages," with the essential syntax, guidelines, and
examples on the right page and the perspective and extra explanation on the
left page. This helps you learn faster by reading less... and this is the ideal
reference format when you need to refresh your memory about how to do
something.

What you'll learn in this book


• In section 1, you'll learn the concepts and terms that you need for web
programming. You'll learn how to use the MVC pattern to structure your
web applications. And you'll learn how to use the NetBeans IDE with a
Tomcat server to develop servlets and JSPs for web applications. When
you're done with this section, you'll be ready to learn how to code and run
servlets and JSPs on your own computer.
• In section 2, you'll get a crash course in HTML and CSS, which is essential
to the use of JSPs. Then, you'll learn the skills for creating servlets and JSPs
that you'll need for almost every application. These chapters move from the
simple to the complex as they show you how to work with servlets, JSPs,
sessions, cookies, JavaBeans, Expression Language (EL), the JSP Standard
Tag Library (JSTL), and custom JSP tags.
• In section 3, you'll learn how to use both JDBC (an older access method)
and the newer Java Persistence API (JPA) to work with a database. Since
MySQL is a popular open-source database that is commonly used for web
applications, this section shows how to work with it, but these principles can
be applied to the use of any database.
Introduction XIX

• In section 4, you'll learn the advanced servlet and JSP skills that you
will need for certain types of web applications. This includes the use of
JavaMail, SSL, authentication, encryption, HTTP, listeners, and filters.
Then, it ends with an introduction to JavaServer Faces (JSF), an alternate
approach to JSP. Since we designed the chapters in this section to work
independently of each other, you can read them in any order you want. This
makes it easy to learn new skills whenever you need them.
• To complete your Java web programming skills, section 5 presents an
e-commerce website that puts the skills presented in the first four sections
into context. This downloadable application illustrates best practices
and provides code that you can use in your own applications. Once you
understand how this website works, you will have all the skills you need for
creating your own web applications.

What operating systems this book supports


The software you need for developing web applications with servlets and JSP
is available for Windows, Mac OS X, and Linux. If you're using Windows, you
can use appendix A to download and install this software. If you're using Mac
OS X, appendix B shows how to download and install this software. If you're
using another platform such as Linux, you probably already know how to install
this software! If not, you can use appendix B as a general guide and search the
Internet for more information if you need it.

How to get the software you need for this book


You can download all of the software that you need for this book for free
from the Internet. To make that easier for you, appendix A (PC) and B (Mac)
show how to download and install the software for this book. This software
includes Java SE, NetBeans, Tomcat, MySQL, and MySQL Workbench.

How our downloadable files make learning easier


To make learning easier, you can download the source code, files, and
databases for all the web applications presented in this book from our website
(www.murach.com). This includes the Music Store e-commerce application.
Then, you can view the complete code for these applications as you read each
chapter; you can compile and run these applications to see how they work; and
you can copy portions of code for use in your own web applications.
You can also download the starting points and solutions for the exercises
in this book. That way, you don't have to start every exercise from scratch.
This takes the busywork out of doing these exercises. As a result, you get more
practice in less time. In addition, if you encounter a problem, you can easily
check the solution. This helps you to keep moving forward with less chance that
you'll get stuck on a minor issue. For more information about these downloads,
please see appendix A (PC) or appendix B (Mac).
XX Introduction

Support materials for trainers and instructors


If you're a corporate trainer or a college instructor who would like to use
this book for a course, we offer an Instructor's CD that includes: (1) PowerPoint
slides, (2) test banks, (3) objectives, (4) additional exercises that aren't in this
book, (5) solutions to those exercises, (6) projects, and (7) solutions to those
projects.
To learn more about this Instructor's CD and to find out how to get it, please
go to our website at www.murach.com. Or, if you prefer, you can call Kelly at
1-800-221-5528 or send an email to kelly@murach.com.

Please let us know how this book works for you


When we started the first edition of this book, our goal was to teach you
how to develop real-world web applications with servlets and JSPs as quickly
and easily as possible. Now, with this third edition of this book, we hope we've
taken that to a new level. So if you have any comments, please email us at
murachbooks@murach.com.
Thanks for buying this book. Thanks for reading it. And good luck with your
web programming.

Joel Murach
Author
ection

Get started right


The three chapters in this section provide the background information that
you need for developing web applications with servlets and JavaServer
Pages (JSPs). In chapter 1, you'll learn what web programming is and how
servlets and JSPs work. In chapter 2, you'll learn how to use the MVC
pattern to structure a web application that uses servlets and JSPs.
Then, in chapter 3, you'll learn how to use the NetBeans IDE
(Integrated Development Environment) to work with the HTML, servlet,
JSP, and XML files that make up a servlet/JSP application. In addition,
you'll learn how to use NetBeans to run a Java web application on a
Tomcat server that's running on your computer.
An introduction to web
programming with Java
This chapter introduces some concepts and terms that you should learn before
you start web programming with servlets and JavaServer Pages (JSPs). In addi­
tion, it describes three approaches that you can use for developing Java web
applications. Finally, it describes some software that you can use to develop
and deploy serv let/JSP applications.

An introduction to web applications ....................................4


A typical web application ................................................................................4
The components of a web application .............................................................6
How static web pages work .............................................................................8
How dynamic web pages work ...................................................................... 10
Three approaches for Java web applications ................... 12
Servlet/JSP ..................................................................................................... 12
JSF.................................................................................................................. 12
Spring Framework ......................................................................................... 12
An introduction to servlet/JSP web development ............ 14
The software components.............................................................................. 14
The architecture ............................................................................................. 16
The standard directories and files ................................................................. 18
Software for developing Java web applications ...............20
IDEs for developing Java web applications ...................................................20
Web servers for Java web applications .......................................................... 22
Database servers for Java web applications................................................... 22
Tools for deploying Java web applications ................................................... 24
Perspective ...........................................................................26
4 Section 1 Get started right

An introduction to web applications


A web application is a set of web pages that are generated in response to
user requests. The Internet has many different types of web applications, such as
search engines, online stores, auctions, news sites, discussion groups, and games.

A typical web application


Figure 1-1 shows the first two pages of the shopping cart application that's
available from www.murach.com. Here, the first page presents some information
about our Java book. This page contains an Add To Cart link. When you click on
this link, the web application adds the book to your cart and displays the second
page, which shows all of the items in your cart.
The second page lets you change the quantity for an item or remove an item
from the cart. It also lets you continue shopping or begin the checkout process.
In this book, you'll learn all the skills you need to create a shopping cart applica­
tion like this one.
If you take a closer look at these web pages, you can learn a little bit about
how this application works. For the first page, the Address box of the browser
shows an address that has an htm extension. This means that the HTML code for
this page is probably stored in a file with an htm extension.
In contrast, the Address box for the second page shows the address of a
servlet that was mapped to the ordering/cart URL. This means that the HTML
code for this page was generated by a servlet. After the servlet address, you can
see a question mark and one parameter named productCode that has a value of
"htm5". This is the parameter that was passed from the first page.
Chapter 1 An introduction to web programming with Java 5

The first page of a shopping cart application


CJ @}

--
I:] Murach'sJava Progammi x

Cl
:=·
n1urach.cor11/books/javp/index.htm
Apps For quick acces�, place your bookmarks here on the bookmark� bar. Import bookmark� now... L] Other bookmarks

Home I Books I Dov,nloads I Trainers I Instructors I Customer Service I view cart I


Murach's Java Programming
by Joel t,lu ra ch
23 chapters, 802 pages, S40 illustrations
Published November 2011
ISBN: 978-1-890774-65-'3

Book price: S57.50; SAVE 30%, now just S4-0.25


eBook price: S47.50; SAVE 30%, nov, just S33.25
Book• eBook: S67.50; B-est Value! SAVE 30% 1 now Just 547.25

"f Jove your Java book. ft cuts :right to the essential information,
provjding the perfect balance betli'een too many details and too
little information. I bought another wel/-knovl'n Java book, but I
spent several hours trying to tearn what r learned from your book
in about 45 minutes." I add book I
I add ebook I
FREE do1Nnload of
sample chapters That's what one developer wrote us about an earlier edition of our
FREE download of the
�ook applications
core Java book. Now, you can expect th1at same practical, time­
saving approach in the current edition that covers the latest
I add both I
'.'\/hat soft,,vare you release of Java Standard Edition, Java SE 7 (or JDK 1.7).
More about the eBook
n��r1

The second page of a shopping cart application


CJ @}
Cl Mike Murach & AssociatE: x
Cl n1urach.cor11/ordering/cart?productCode = htmS --
:=· Apps For quick access, place your bookmarks here on the bookmark� bar. Import bookmark� now... L] Other bookmarks

Home I Books I Oov1nloads I Trainers I Instructors I Customer Service I view cart I


Your cart

Qty Description

!1 I [ Update I Murach's Java Programming [ Remove j


E � [ Update I Murach's HTML5 and CSS3 [ Remove j
To change the quantity, enter the new quantity and click on the Update button.

[ Continue Shopping ] I Proc eed t o Checkout ]

Do you have a pron1otion code to apply to this order?


If so, enter it here: [ =1
Other books related to what you just picked

Figure 1-1 A typical web application


6 Section 1 Get started right

The components of a web application


Figure 1-2 shows the basic components that make up a web application.
Because a web application is a type of c lientlserver application, the compo­
nents of a web application are stored on either the client computer or the server
computer.
To access a web application, you use a web browser that runs on a client
computer. One widely used web browser is Google Chrome, and a popular
alternative is Mozilla Firefox.
The web application itself is stored on the server computer. This computer
runs web server software that enables it to send web pages to web browsers.
Although there are many web servers, the Apache Software Foundation's Apache
HTTP Server is one of the most popular. Many developers refer to it just as
Apache.
Because most web applications work with data that's stored in a database,
most servers also run a database management system (DBMS), which is also
known as a database server. Two of the most popular for Java development are
MySQL and Oracle. When you use a database server, it doesn't have to run on
the same server as the web server software. In fact, a separate database server is
often used to improve an application's overall performance.
Although this figure shows the client and server computers connected via the
Internet, this isn't the only way a client can connect to a server in a web applica­
tion. If the client and the server are on the same Local Area Network (LAN), they
function as an intranet. Since an intranet uses the same protocols as the Internet,
a web application works the same on an intranet as it does on the Internet.
Chapter 1 An introduction to web programming with Java 7

Components of a web application


Client Server
computer computer

Internet

- connection
- I

Web Web server


browser Database server

Description
• Web applications are a type of client/server application. In a client/server applica­
tion, a user at a client computer accesses an application at a server computer. For a
web application, the client and server computers are connected via the Internet or
an intranet.
• In a web application, the user works with a web browser at the client computer. The
web browser provides the user interface for the application. One widely used web
browser is Google Chrome, but other web browsers such as Mozilla Firefox and
Internet Explorer are also widely used.
• A web application runs on the server computer under the control of web server
software. The Apache server is one of the most widely used web servers.
• For most web applications, the server computer also runs a database management
system (DBMS), which is also known as a database server. For servlet and JSP
applications, Oracle and MySQL are two of the most popular database management
systems.

Figure 1-2 The components of a web application


8 Section 1 Get started right

How static web pages work


HTML (Hypertext Markup Language) is the language that the browser
renders to the web pages that make up a web application's user interface. Some
web pages are static web pages, which are the same each time they are viewed.
In other words, they don't change in response to user input.
Figure 1-3 shows how a web server handles static web pages. The process
begins when a user at a web browser requests a web page. This can occur when
the user enters a web address into the browser's Address box or when the user
clicks a link that leads to another page. In either case, the web browser uses a
standard Internet protocol known as Hypertext Transfer Protocol (HTTP) to send
a request known as an HTTP request to the website's server.
When the web server receives an HTTP request from a browser, the server
gets the requested HTML file from disk and sends the file back to the browser
in the form of an HTTP response. The HTTP response includes the HTML
document that the user requested along with any other resources specified by the
HTML code such as graphics files.
When the browser receives the HTTP response, it renders the HTML
document into a web page that the user can view. Then, when the user requests
another page, either by clicking a link or typing another web address in the
browser's Address box, the process begins again.
Chapter 1 An introduction to web programming with Java 9

How a web server processes static web pages


Client Server
HTTP
request

HTTP
response

Description
• Hypertext Markup Language (HTML) is the language that the web browser converts
into the web pages of a web application.
• A static web page is an HTML document that's stored in a file and does not change
in response to user input. Static web pages have a filename with an extension of
.htm or .html.
• Hypertext Transfer Protocol (HTTP) is the protocol that web browsers and web
servers use to communicate.
• A web browser requests a page from a web server by sending the server a message
known as an HTTP request. For a static web page, the HTTP request includes the
name of the HTML file that's requested.
• A web server replies to an HTTP request by sending a message known as an HTTP
response back to the browser. For a static web page, the HTTP response includes
the HTML document that's stored in the HTML file.

Figure 1-3 How static web pages work


Another random document with
no related content on Scribd:
the weeks consumed by the trip, an existence which must have been
somewhat like that of Noah’s family in the Ark.
There was not, as I have mentioned, any means of keeping foods
fresh, nor was there even ice water to be had on those boats. We
used entirely, even for drinking, the muddy river water, which was
hauled up in buckets on the barber side of the boat, while the
steward was emptying refuse to the fishes on the pantry side. The
passengers became more or less intimate, necessarily, on a trip
such as I am attempting to describe. There was no place to sit but in
the general cabin, the sleeping rooms being so cramped. There was
no library, very little reading, but much fancy work, mostly on canvas,
footstools and bell-pulls. A bell-pull, you may want to know, was a
long band about three inches wide; it was hung from the parlor
cornice and connected with a bell in the servant’s region; it was quite
the style to embroider them in gay vines and flower designs.
The elderly ladies knit fine thread nightcaps, collars and lace.
Really some of the “old lady” work was quite handsome. Thus
fingers were kept busy, while gossip and interchange of bread and
cake recipes entertained the housewives who had never heard of
cooking schools and domestic science. Our trip necessarily
embraced at least one Sunday. I remember my father had a dear old
relative of the deepest dyed Presbyterian type (father of the late Dr.
T. G. Richardson), who always on his river trips landed wherever he
happened to be on Saturday and on Monday boarded another boat
(if one came along), his scruples forbidding Sunday travel.
American Stagecoach.

(From “Forty Etchings, from Sketches Made with the Camera Lucida in North
America in 1827 and 1828,” by Captain Basil Hall, R. N.)

Arrived at the end of our river journey, father chartered a whole


stage to take his family a two days’ trip into the heart of the blue
grass region. Nine passengers filled the interior of the coach, and
four or five, if need be, could ride on top. The rumble (we always
called it boot) was filled with baggage. The vehicle had no springs,
but was swung on braces, which gave it a kind of swaying motion
that always made me sick. However, we managed to start off in fine
style, but every time there was a stop to change horses all of us
alighted, stiff and tired and hot, to “stretch our legs,” like Squeers in
Dickens’ “Nicholas Nickleby.” At noon we rejoiced to hear our
coachman’s horn, a grand, loud blast, followed by toot, toot!—one
toot for each passenger, so the tavern man would know how many
plates to lay, and his wife how many biscuits and chicken legs to
have ready. We always made out to spend the one night of the
journey at Weissiger’s tavern in Frankfort, the best tavern in all the
land. We had a leisurely breakfast the following morning and were
refreshed in body and soul for the last lap of our journey.
Late afternoon the stage winds up a hill, and in a woods pasture
and surrounded by blue grass meadows the gable end of a red brick
house can be seen. My dear, tired mother puts her head out of the
window, “Driver, blow your horn.” A great blast sounds over the
waving grass and blossoming fields, and we know that they know we
are coming. Tired as the horses are after the long, hard pull; tired as
the coachman must be, he cracks his whip, and we gallop up the
shady lane to the dear old door as briskly as though we were fresh
from the stable. Long before we are fully there, and the steps of the
nine-passenger coach can be lowered; long before the boys can
jump off the top, a host of dear faces, both white and black, is
assembled to greet us. As a little child I always wondered why it was,
when the occasion was so joyful, and all of us tumbled from that
stage so beaming and happy, that as my aunt folded my mother in
her arms, they both wept such copious tears. Now I know.
XX
HOTEL AT PASS CHRISTIAN IN 1849

If there is a more restful spot on earth than a comfortable rocking-


chair on a deep veranda, with a nearby view of the dancing waters of
the gulf through a grove of tall pines, commend me to it. A whole
month on the west coast of Florida, all sand underfoot, pines and
oaks overhead, is ideal for fagged-out, tired-out, frayed-out humanity
from busy cities. This is not an advertisement, so I do not propose to
tell where six people from six different and widely separated parts of
the country last year dropped down from the skies, as it were, upon
just such a delightful straight mile of gulf coast.
One halts at a “turpentine depot” and takes a queer little tram to
the Gulf, seven miles away. Tram is hauled over wooden rails by two
tired nags whose motions suggest the lazy air of the pines. It is
loaded with the baggage—crates of hunting dogs—(fine hunting
abounds), the mail bag, some miscellaneous freight and finally the
passengers.
The country hotel is pine; ceilings, floors, walls are pine, the home-
made and built-in furniture is pine; a big fire, roaring in the open
fireplace if the day is chilly, is also made of pine—the rich, red
Florida pine, ever so much richer in color and in turpentine than the
boasted Georgia article. With the fish swimming in front of this hotel
and the birds flying behind, and rabbits running in both directions, it
goes without saying the table is above the average.
Here on the broad verandas, as we rock and dream the lazy days
away, visions visit me of the old hotel at Pass Christian in the forties.
The oaks and three China trees in front of the veranda, and the view
of the nearby waters, the whistle of mocking-birds among the china
berries (thank heaven! sparrows have not found this Elysium) lend
additional force to the semblance. One old lady, who hunts not,
neither does she fish, rocks on the sunny veranda and dreams, as is
the wont of those who have lived beyond their day and generation.
She brings forth from a long-forgotten corner of memory’s closet a
picture covered with the dust of years, and lovingly brushes away the
dimness, when behold! old Pass Christian, dear old Pass Christian,
before the day of railroads and summer cottages, before the day of 6
o’clock dinners and trailing skirts, of cotillion favors and abbreviated
bathing suits.
The old hotel was built with a wing or extension at each end, which
formed with the main building three sides of a square. There was no
attempt at landscape gardening; not even a rosebush or an oleander
decorated the little court. No plaster Apollos and Dianas such as
were seen peeping about the shrubbery of the various cottages (like
the De Blancs’ and Ducayets’) that dotted in those days the old
bayou road, and were considered so very decorative, but plain sand
and scrub such as meet my eye to-day on this little frequented part
of the Florida Gulf Coast. There was no beach driving or riding of
gay people then—none here now.
I fly back to the summer of ’49, and live again with the young girls
who made life one long summer’s day. We walked the pier, the
image of one before my eyes now, to the bath-houses in muslin
dresses. Bathing suits were hideous, unsightly garments, high neck,
long sleeves, long skirts, intended for water only! The young girls
returned under parasols and veils. How decorous! No baigneuse
decolletée to be seen on the beach. Our amusements were simple
and distinctly ladylike. There was no golf or tennis, not even the
innocent croquet, to tempt the demoiselles to athletics, so they
drifted more to the “Lydia Languish” style.
There was no lack of beaux who came, more than enough to “go
round,” by the Saturday boats, in time for the weekly hop—danced
all Saturday night and returned to weekly drudge (as they called it) in
the city. The bonbons and flowers they brought vanished and faded
long before the little boat with its freight of waving hats and
handkerchiefs faded in the twilight of a summer Sunday.
Also there come to my dream two dainty Goodman sisters,
wonderful and most accommodating musicians they were. One was
already affianced to her cousin, George Nathan. He was a
prosperous business man at that time. I doubt if even his name is
known among his thrifty race in New Orleans to-day. He carried off
his accomplished wife to Rio Janeiro, and made his home in that
country, which was as far away to us then, as the North Pole is to-
day. The younger sister met that summer at the Pass and eventually
married E. C. Wharton, an attaché of the Picayune, whose articles
were signed “Easy Doubleyou.” He was soon dancing attendance on
the pretty, curly haired girl. I remember how he wandered around
with pad and pencil, and we girls were horribly afraid of being put in
the Picayune. No reason for fear, as it was before the dawn of the
society page and personal column. The Whartons drifted to Texas
during the war, and at Houston they found already a host of stranded
Louisianians; but “Easy Doubleyou” had a government appointment
of some kind. The rest of us were simply runaways.
There, too, was Dick Taylor, propelled in a wheel chair over that
hotel veranda, an interesting convalescent from severe illness, or
perhaps a wound, I do not recall which, his valet so constant in
attendance that we wondered how the young man ever got an
opportunity to whisper sweet nothings into the ear of lovely Myrtle
Bringier—but he did! And that was the fourth engagement of the
season that culminated in marriage, which signalizes the superior
advantages of a hotel veranda, and most especially that of dear old
Pass Christian. Dick Taylor had a magnetic personality, which
overshadowed the fact (to paraphrase a Bible text) he was the only
son of his father, and he the President.
In New York some years ago “The Little Church Around the
Corner,” still garnished with its wealth of Easter lilies and fragrant
with spring bloom, threw wide its portals for the last obsequies of this
loved and honored Confederate general. In that throng of mourners
was one who had known him in his early manhood on the veranda of
that old Pass Christian hotel, and whose heart had followed his
career with ever-increasing admiration and veneration even unto the
end. I lay aside my old picture forever. Alas! it remains “only a dream
at the best, but so sweet that I ask for no more.”
XXI
OLD MUSIC BOOKS

I wonder how many old ladies start to go through an unused hall


closet, to make room for an accumulation of pasteboard boxes too
good to throw away, and hampers too strong to discard, and in that
long-closed closet, which a junk man with push-cart is waiting to help
clear out, find a treasure, long since buried under piles of trash,
mourned for, and, as in the case of many departed things, at length
given up for lost—then forgotten. In just such a dark closet, from
beneath a pile of old magazines (what they were kept and stored for
goodness knows) and crazy bits of bric-a-brac, that nobody but a
junk man (not even Salvation Army men, who are getting to be
mighty choosy, by the way) would cart off, I found two bruised music
books.
One dated back to 1847, when I was a schoolgirl in New Haven,
and played with great éclat “La Fête au Couvent” quadrilles,
purchased of Skinner & Co., Chapel Street. Chapel Street still exists,
but Skinner & Co. are buried in the dust of more than sixty years. I
cannot play “La Fête au Couvent” or any other fête now, but I can
close my eyes and see the lovely young girls in the school music
room whirling away to the music of the inspiring cotillion. Alas! Alas!
Time has whirled every one of them away and stiffened the nimble
fingers that danced so merrily over the keys.
In those far away days that are as yesterday to my dreaming there
were “Variations” of every familiar melody. Variations that started with
the simple air and branched off into all sorts of fantastic and involved
and intricate paths. “Oft in the Stilly Night,” “’Tis Midnight Hour,”
“Twilight Dews,” “Low-Back’d Car,” “The Harp That Once Thro’ Tara’s
Halls,” “Oh, Cast That Shadow From Thy Brow,” and so on and on,
whole pages of “Variations,” now dim with age, but every blessed
note brings to me the faces and voices of those long stilled in death.
One sweet young girl played “The Harp That Once Thro’ Tara’s
Halls” and “’Tis Midnight Hour” so charmingly that my eyes were
dimmed when I turned the leaves of the school-day music book, for
her fate was saddest of all—an inmate for years of an insane
asylum. Another who sang as she played the “Low-Back’d Car” so
delightfully (she was half Irish) died suddenly of yellow fever. Still
another associated with “Oh, Cast That Shadow From Thy Brow,”
played the melody on a guitar, accompanied by her sweet young
voice. Alas! She, too, is gone where they play on harps and there are
no shadowed brows. So, on and on to the bitter end, and with a sigh
I close the first chapter of my musical reminiscences that have lain
dormant so many, many years.
The fashion of dedicating bits of music to some well-known person
—need not be a musician, either, but a body of some note—has
passed away with the one-button glove and the green barège veil of
sixty years ago. In the ’50s it was quite common, and my dear music
book of that date holds ever so many dedicated polkas and
mazourkas. The very front leaf has a picture of a wonderfully
crocheted kind of a serpent with a man’s head, rather a shocking
thing, “Sea Serpent Polka,” dedicated to Miss Rose Kennedy, by M.
Strakosch. Dear Rose used to play it for us. It was not an inspiring
bit of music, but her wonderfully deft touch would make melody out
of anything that had crochets and quavers in it.
There is, a few pages further, another dedication to the
incomparable Rose, “Grande Polka de Concert,” by Wallace. Miss
Lou Gross, a most accomplished musician, daughter of the noted
surgeon, Dr. Samuel Gross, was honored by Strakosch in the
“Kossuth Galop,” a galloping thing, much in the Strakosch style,
which predominated in those days. Strakosch believed in a grand
“send off” of his innumerable productions. There’s “Carnival de
Paris,” dedicated to Mme. Caroline Arpin (I did not know of her) and
“Flirtation Polka,” to Mme. Lavillebeuvre, who was a delightful pianist
and merited something more inspiring than that “Flirtation.”
Then Wallace dances on the pages with a “Polka” adorned with
the name of Mlle. Dumilatre, and Ed Armant dedicates “La Rose
Polka” to Miss Augusta Slocomb. I don’t think Armant wrote music;
he “got it done,” as the saying is. That was not an unusual feat; a
valse was dedicated to Miss Philomène Briant, by George
McCausland, and he was ignorant of a note in music—he “got it
done.” P. A. Frigerio honored Miss Sara Byrne by the dedication of
“La Chasse Polka.” Miss Sara was a decided belle in the ’50s, so a
bit of music with her name attached found rapid disposal. Also, a
belle of the ’50s was Miss Estelle Tricou. Lehman, chef d’orchestre
at the opera house, wrote “Souvenir de Paris” in her honor. Miss
Estelle was bright and sparkling and beautiful, so was much in
evidence. George W. Christy wrote more than one of his “starry”
verses to “E. T.,” and they were printed in the Picayune. George was
not noted for self-effacement and modesty. His signature always
appeared in full to his sentimental effusions.
Lehman dedicated his “Clochettes Polka Mazourka,” a fine,
inspiring bit of dance music it was, too, to Mme. Odile Ferrier, and
“La Valentine Polka,” another charming, catchy dance piece, to Miss
Anaïs Boudousquie. There was Mme. Angélina, a new French
importation, whose specialty was the new dances that nobody else
could teach. She was immortalized by “L’Esmeralda Nouvelle Danse
de Salon.” We pupils had to learn some new steps and flourishes to
be able to make successful début, after All Saints’ Day, for it was
decreed “L’Esmeralda” was to be most popular. Everybody, even
some stout old ladies that did not mean to be relegated to back
seats, and passé beaux who were fast becoming clumsy and awfully
hard to dance with, took dancing lessons on the sly of Mme.
Angélina, not to mention the young girls, débutantes and such, that
went in small installments to her tiny room in Royal Street....
After this seeming digression I turn a leaf in the old music book to
dedications to Mme. Boyer, “Mazourka Sentimentale,” by the fertile
Strakosch, and here, too, “La Valse Autrichienne” by a new name—
E. Johns. Mme. Boyer was the fashionable teacher of music. Both
these dedicated pieces we scholars had to learn, and both bits,
besides a dozen other bits a thousand times more difficult and
intricate, like Gottschalk’s “Bamboula,” for instance, are so spotted
with black pencil marks they are a sight! For the madame did not
make a suggestion as to technique or expression or anything else in
the musical mind that was not emphasized by a pencil mark on the
page.
I find that most of this music was published by Mayo, No. 5 Camp
Street; by Lyler & Hewitt, 39 Camp Street. Lehman published his
own work at 194 St. Anne Street.... I am not half through, but I am
weary of looking over these old music books. So many memories
cluster about every page—memories of lovely dances with delightful
partners. Oh! That grand valse à cinq temps, the music of which was
never printed, and no band but Lehman’s band could play it, and
nobody taught the whirling steps but Mme. Angélina. Memories of
sweet girls, now old and faded, or, better than that, listening to the
“Music of the Spheres.” Memories of painstaking professors whose
pencil marks are all that is left to bring forcibly to mind their patient
personality. I turn the last leaf, and lo! here is a unique bit of music
and information—“The Monterey Waltz,” by Eugene Wythe Dawson,
a little Texas boy, who dedicates it to the little musicians of his own
age (eight years) in the sister States! I do not remember anyone who
essayed to render the “Monterey Waltz”—I never did—but Eugene
Dawson was still playing the piano in Texas during the war, proving
possibly our grandfather’s dictum, “A man who plays the piano is
mighty little account for anything else.”
We don’t think so now. I would be glad for a musician, male or
female, in this house to render for me the sweet musical numbers
that once made my young heart bound.
XXII
THE SONGS OF LONG AGO

How the ballads of our youth are, in memory, merged into the
personality of those who sang them! How, as we recall the simple
rhymes, the sweet voices of departed friends clothe them in melody.
The songs of my early years come to me to-day with more freshness
than the songs I heard yesterday, and with them come more vividly
to mind the voices and faces of those long-gone friends than come
the faces of those of to-day.
How many of us can recall “Blue-eyed Mary”? the little ballad with
which my mother always quieted me to rest. The pitiful little song!
And in my childhood days, too, mammy rocked me to sleep with “Ole
Grimes is daid, dat good ole man.” I never hear “Blue-eyed Mary” or
“Old Grimes” now, nor have I for more than threescore years and
ten, they are both so buried in oblivion, though I can repeat every
word of each, they were so nestled and rocked into my baby life.
When my father’s home was on Customhouse Street Duncan
Hennen lived directly opposite. Mrs. Hennen was a dashing beauty.
She had a sister from Tennessee visiting her, who had a powerful
voice, and she sang “Old Rosin the Beau” and “Life on the Ocean
Wave” with all the abandon of a professional. My father admired her
style prodigiously, but my mother thought it too robust. “The Carrier
Dove—fly away to my native land, sweet dove,” and “Twilight Dews,”
she pronounced more ladylike. (How often we used that word
“ladylike.” We rarely hear it now.) I must have been a very small “little
girl” when I heard Wallace, in concert, sing “The Old Arm Chair.” No
one since Wallace ever sung that touching, homely ballad so
beautifully. Once having heard his sympathetic rendering, one
always associates the song with William Wallace.
I think it has been full sixty years since that song and “Farewell to
Tom Moore,” by Byron, have been heard. And “Twilight Dews,” oh,
my! and “Shells of the Ocean”—“One summer’s day in pensive
thought,” etc. Young girls played their accompaniments and tossed
their ringlets and sang those ditties to enraptured swains, who often
stood back of them, holding the candle at the proper angle and
turning the leaves! How it all comes back to this dreaming old lady,
who never sang, but who dearly loved to listen to her more gifted
friends....
In the Cajin settlement on the border of which I occasionally visited
there was a family of Lafitons—I boldly give the name, for the two
sons, Lafiton fils and Pete, never married, and all the family died
years and years ago, but there was a lovely sprig of a girl,
Amenaide, who possessed a fine voice and no doubt would have
made her mark if she had had the necessary training, but she was
one of the flowers “born to blush unseen.” I don’t think she knew one
note of music. Of course, a guitar, much more a piano, was beyond
her reach. She sang the sweet old French melody, “Fleuve du Tage,”
delightfully. I wonder now where she ever heard it. For years after
when I heard the song Amenaide rose before me, and with her the
impression that she was not equaled.
There was another touching little ballad, in the days that were,
“We Have Been Friends Together,” and that tender “Good-by,” who
ever sings them now? Nobody, unless it be some old lady with
quavering voice, who sings them in her heart while she dreams of
the sweet girls of “Long, long ago” who have vanished.
“I Cannot Sing the Old Songs,” and “When Stars Are in the Quiet
Skies” were two of the songs we loved to hear in the days before
“Dixie” and “The Volunteer” and “The Bonnie Blue Flag” captured the
voices of so many of our sweet singers.
Some of us remember Mollie Haynes, who became the wife of
Col. Charles D. Dreux, and none can recall her charming personality
without a thought of the superb voice she possessed. “Ave Maria,
Ora Pro Nobis”—none that I knew could render that prayerful melody
with the pathos of Mollie Dreux. We all remember that Col. Dreux
was the first Confederate officer from Louisiana who fell in battle,
and no subsequent funeral was more largely attended than was
Charles Dreux’s. “Joys That We’ve Tasted” brings to mind a popular
singer in the “Long Time Ago,” Mrs. George D. Prentice, of Kentucky.
How the names and the very people come thronging my mind as I
recall these old melodies in which they are associated.
A few years since, listening to the well-trained voice of a
professional, as she rendered some intricate, superlative kind of
music, that did not in the least appeal to me, I ventured to ask if she
would favor us with “Ben Bolt.” She graciously consented. And she
rendered that simple old ballad that every child whistled or hummed
when I was a child, with so many trills and bravuras, and I don’t
know what else in the vocal line, that I was lost in amazement.
Svengali himself could not have idealized to the same extent. Poor
“Sweet Alice” was buried under such an avalanche of sound that one
could not recognize the “corner, obscure and alone,” where she was
supposed to rest under a “slab of granite so gray.”
So, perhaps, in the march of improvement, where none sing
unless they possess a voice that would electrify a whole opera
house audience, it is well the dear old songs of long ago are not
resurrected and amplified to suit the tastes and requirements of to-
day. I recall though, with a thrill of tender memory, hearing Jenny
Lind sing “Home, Sweet Home”—just the simple ballad—without a
single flourish when she was in New Orleans in 1851. I was in deep
mourning and did not dream I would have the pleasure of hearing
her, but a friend secured a loge grillée, and insisted upon my going,
accompanied by my brother. It was all arranged so courteously and
so sympathetically and so kindly that I could not refuse, and thus I
heard that incomparable artist sing “Home, Sweet Home.”
No longer can mother sit in her “old arm chair” waving a turkey tail
fan warm summer evenings, and be comforted and soothed by
sweet warblings of her girls at the piano. No longer can the tired
father call for his favorite, “Oh! Would I Were a Boy Again,” or “Rock
Me to Sleep, Mother,” or Mrs. Hemans’ “Bring Flowers, Fresh
Flowers,” the sweet old flowers that all girls were singing sixty years
ago. The old mothers and fathers, the bright young daughters are
scarce buried more deeply or mourned more deeply than are the
songs of long ago.
XXIII
A RAMBLE THROUGH THE OLD CITY

In the days of which I write New Orleans bore a very different


aspect from the present, and it may be well for me to take my
readers on a gossipy ramble through the thoroughfares which I so
often traverse nowadays in my thoughts.
Canal Street in the early forties was, par excellence, a resident
street. From Camp and Chartres Streets, way back as far as
sidewalks were flagged or bricked, which was only a few blocks,
Canal Street was lined with homes, side by side, often without even
an alley to separate them, as though land was scarce and one need
economize space, whereas just beyond was land in plenty, but no
sidewalks or easy approaches to speak of. From Camp Street to the
levee were, as I remember, large wholesale business houses,
convenient to the shoppers of large supplies, who arrived at regular
intervals from their plantations on Belle Creole, or some other coast
packet, frequently retained their quarters on the boat the short time it
was in port, and so monsieur and madame could accomplish their
necessary shopping, untrammeled by the elegancies and
inconvenient hours of a hotel.
Things were conducted on a very liberal basis in those days. I
have a liking for that old way—it was so debonair and generous,
putting the captain on the same social standing as his guests.
On the lower side of Canal Street, about where Holmes’ store now
stands, were more homes, in a row, all the houses exactly alike, with
narrow balconies stretching clear across the fronts, in a most
confidentially neighborly way. The lower floors were doctors’ or
lawyers’ offices or exchange brokers’. Fancy goods, dry goods, retail
shops, in fact of every kind, were on Chartres or Royal Street; none
on Canal. R. W. Montgomery had his home also on that fashionable
thoroughfare.
Christ Church was on the corner of Baronne and Canal, and Dr.
Laycock was the pastor at the date of which I write, and, with few
exceptions, all these families were of his flock.
Lower Camp Street was occupied mostly by exchange brokers’
and such offices. The Sun Mutual Insurance Company had a
conspicuous sign on a modest two-story brick building which any
insurance structure to-day would put to shame.
If it is near Christmas time, when we are taking this gossipy
ramble, we might meet a flock of turkeys marching up Camp Street,
guided by a man and boys with long poles. In those days fowls were
not offered for sale ready dressed or plucked, but sold “on the hoof,”
as we say of cattle. Camp and the adjacent resident streets were, to
use another Westernism, a favorite “turkey trot.” Those turkeys may
have trotted miles. Goodness knows whence they took up the line of
march—presumably at some boat landing—but they were docile as
lambs and in good condition. No roast turkey gobbler, or, better still,
boiled turkey hen with oyster dressing, tastes now like the ones
mother had on her table when I was a child and clamored for the
drum-stick. What does taste as good to us old folks to-day? Nothing!
Absolutely nothing!...
In Exchange Alley (it may have a new name now, since Triton
Walk and Customhouse Street and others of the old days have been
rechristened) my father and a number of other “attorneys at law,” as
their signs indicated, had offices. Mr. Wharton was one, and I also
recall two Hebrew beaux of that date who were neighbors of my
father’s, A. K. Josephs and M. M. Cohen. Nobody knew their given
names. Beyond Camp Street, near Magazine, Mme. Shall kept a
boarding house. It was a popular hostelry for gentlemen. Ladies did
not board, except (to use Susan Nippers’ language) as temporaries.
Exchange Alley.

Visitors to the city “put up” at the St. Charles Hotel, in the hands of
Colonel Mudge. St. Charles was the best hotel even then, comparing
favorably with the Galt House, in Louisville, under the management
of that prince of hosts, Major Aris Throckmorton—which is saying
volumes for the St. Charles. In the season flocks of Nashville,
Louisville and Cincinnati belles descended upon New Orleans, sat in
gorgeous attire and much chatter of voices on the divans under the
chandelier of the St. Charles parlor, while the kindly fathers and
insinuating brothers, bent on giving the girls a good time, foraged
about the ample rotunda, captured, escorted in and introduced many
eligible beaux found sauntering around that fascinating rendezvous.
Up Carondelet Street—one could not find the location on a city
map now, for, as I remember, the streets were not named—were
suburban homes, all about, quite remote and countrified. Judge John
N. Duncan lived in one of those cottages. There was a grand, big
yard surrounding it, with fig trees, hedges, rosebushes and vines, a
perfect bower of delight to us children. Rose, the only daughter, was
a lifelong friend of mine. She became the first wife of Col. William
Preston Johnston. Nearby lived the Peter Conreys, who gave lovely
lawn parties, that the naughty uninvited dubbed “Feat sham peters.”
Not so very far away, in the neighborhood of Constance and Robin
Streets, there was erected in 1843 Quite a grand residence for the
Slark family. I do not remember much of them in those early days,
though they lived near enough to my father’s to be neighbors. Later
in life my acquaintance with them was more intimate. I recall, though,
quite vividly Mrs. Slark’s visiting card, which I admired prodigiously.
Being a small collector of curios that unique bit of pasteboard was
one of my treasures till I lost it! There seems to have been
considerable latitude in the style of visiting cards about that time—
some were highly glazed and had gilt edges; some were even pink
tinged, but I think Mrs. Slark’s was the ne plus ultra—a bird’s beak
holding a waving pennant, and on its flowing folds was engraved
“Mrs.—Abigail—L.—Slark,” something after the style of the eagle
and E pluribus unum.
I find I am wandering away from that dear old Canal Street of
fragrant memories. Fragrant, though the broad neutral ground was a
wilderness of weeds of dampy growth, and (so our John used to tell
me) snakes! There certainly were frogs after a spring rain. I have
heard their croaks. Further back toward the swamps were deep
ditches, with crawfish sneaking about in them. Fine fishing place for

You might also like