0% found this document useful (0 votes)
13 views

Developing Java Servlets 2nd ed Edition James Goodwill download

The document provides information about the book 'Developing Java Servlets, 2nd Edition' by James Goodwill, including its contents and structure. It covers various topics related to Java Servlets, JSP fundamentals, and web application development. The document also includes links to other related books and resources available for download.

Uploaded by

orichageslo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Developing Java Servlets 2nd ed Edition James Goodwill download

The document provides information about the book 'Developing Java Servlets, 2nd Edition' by James Goodwill, including its contents and structure. It covers various topics related to Java Servlets, JSP fundamentals, and web application development. The document also includes links to other related books and resources available for download.

Uploaded by

orichageslo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Developing Java Servlets 2nd ed Edition James

Goodwill pdf download

https://ebookname.com/product/developing-java-servlets-2nd-ed-
edition-james-goodwill/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Developing story ideas 2nd ed Edition Rabiger

https://ebookname.com/product/developing-story-ideas-2nd-ed-
edition-rabiger/

Fundamentals of project management developing core


competencies to help outperform the competition 2nd ed
Edition James P. Lewis

https://ebookname.com/product/fundamentals-of-project-management-
developing-core-competencies-to-help-outperform-the-
competition-2nd-ed-edition-james-p-lewis/

Fuel Cell Systems Explained 2nd Ed 2nd ed Edition James


Larminie

https://ebookname.com/product/fuel-cell-systems-explained-2nd-
ed-2nd-ed-edition-james-larminie/

Building Law Encyclopaedia 1st Edition David Chappell

https://ebookname.com/product/building-law-encyclopaedia-1st-
edition-david-chappell/
Great Buildings 1st American ed Edition Dk Publishing

https://ebookname.com/product/great-buildings-1st-american-ed-
edition-dk-publishing/

The World of Pompeii 2007 Routledge Worlds Pedar Foss

https://ebookname.com/product/the-world-of-
pompeii-2007-routledge-worlds-pedar-foss/

Deuterocanonical and Cognate Literature Yearbook 2007


The Concept of Celestial Beings Origins Development and
Reception 1st Edition Reiterer

https://ebookname.com/product/deuterocanonical-and-cognate-
literature-yearbook-2007-the-concept-of-celestial-beings-origins-
development-and-reception-1st-edition-reiterer/

Current Clinical Evidence in Ophthalmology 1st Edition


H.W. Roberts

https://ebookname.com/product/current-clinical-evidence-in-
ophthalmology-1st-edition-h-w-roberts/

Surgical Decision Making 6th Edition Mcintyre Md Facs

https://ebookname.com/product/surgical-decision-making-6th-
edition-mcintyre-md-facs/
Organizational Behavior 3rd Edition Michael A. Hitt

https://ebookname.com/product/organizational-behavior-3rd-
edition-michael-a-hitt/

Developing Java
Servlets
James Goodwill

800 East 96th St., Indianapolis, Indiana, 46240 USA


PUBLISHER
Developing Java™ Servlets, Paul Boger
Second Edition EXECUTIVE EDITOR
Copyright © 2001 by Sams Publishing Michael Stephens

All rights reserved. No part of this book shall be reproduced, stored in a ACQUISITIONS EDITOR
retrieval system, or transmitted by any means, electronic, mechanical, photo- Carol Ackerman
copying, recording, or otherwise, without written permission from the pub-
DEVELOPMENT EDITOR
lisher. No patent liability is assumed with respect to the use of the information
Tiffany Taylor
contained herein. Although every precaution has been taken in the preparation
of this book, the publisher and author assume no responsibility for errors or MANAGING EDITOR
omissions. Nor is any liability assumed for damages resulting from the use of Matt Purcell
the information contained herein.
PROJECT EDITOR
International Standard Book Number: 0-672-32107-6 Christina Smith
Library of Congress Catalog Card Number: 00-111799
COPY EDITOR
Printed in the United States of America Cynthia Fields
First Printing: June 2001 INDEXER
04 03 02 01 4 3 2 1 Erika Millen

PROOFREADER
Trademarks Benjamin Berg
All terms mentioned in this book that are known to be trademarks or service
marks have been appropriately capitalized. Sams Publishing cannot attest to TECHNICAL EDITOR
the accuracy of this information. Use of a term in this book should not be Rob Tiffany
regarded as affecting the validity of any trademark or service mark.
TEAM COORDINATOR
Warning and Disclaimer Lynne Williams
Every effort has been made to make this book as complete and as accurate as INTERIOR DESIGNER
possible, but no warranty or fitness is implied. The information provided is on Anne Jones
an “as is” basis. The author and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris- COVER DESIGNER
ing from the information contained in this book. Aren Howell

PAGE LAYOUT
Ayanna Lacey
Heather Hiatt Miller
Stacey Richwine-DeRome
Overview
Contents at a Glance
Introduction 1
1 Web Applications and the Model View Controller (MVC) Design Pattern 7

PART I Servlet Fundamentals


2 Servlet Overview and Architecture 15
3 Servlet Basics 25
4 Servlets and HTML 33
5 Servlet Sessions 41
6 HTTP Tunneling 59
7 Servlets, JDBC, and Inter-Servlet Communications 85
8 Servlets and JavaMail 131
9 Servlet Security 143
10 Servlets and XML 151
11 Servlets and LDAP 163
12 Servlets and Enterprise JavaBeans 189
13 A Servlet Controller 225

PART II JSP Fundamentals


14 JSP Overview and Architecture 235
15 JSP Implicit Objects 247
16 JSP Standard Actions 261
17 Using JavaBeans and JSP Scopes 281
18 Handling JSP Errors 293
19 Custom JSP Tag Libraries 301
PART III Servlet and JSP Web Applications
20 Catalog Case Study 321
21 An LDAP Web Client 347
22 A Stock Trader 363
23 Wireless Application Development Using WAP 385
24 WML/WMLScript Development 397

PART IV Appendixes
A Web Applications and Configuring the Servlet Engine 419
B The javax.servlet Package 429
C The javax.servlet.http Package 461
D The javax.servlet.jsp Package 489
E The javax.servlet.jsp.tagext Package 513
F WML (The Wireless Markup Language) 543
G WMLScript 547
Index 559
Contents
Introduction 1

1 Web Applications and the Model View Controller (MVC)


Design Pattern 7
The Model View Controller (MVC) Design Pattern ..............................8
A Server-Side Implementation of the MVC............................................8
Servlets as MVC Controllers..............................................................9
JSPs as MVC Views ........................................................................10
Summary ................................................................................................10

PART I Servlet Fundamentals


2 Servlet Overview and Architecture 15
Movement to Server-Side Java ..............................................................16
Definition of a Java Servlet ..................................................................16
Practical Applications for Java Servlets ................................................16
Java Servlet Alternatives........................................................................17
Common Gateway Interface ............................................................17
Proprietary APIs ..............................................................................18
Server-Side JavaScript......................................................................18
Microsoft’s Active Server Pages ......................................................18
Reasons to Use Java Servlets ................................................................19
Efficiency..........................................................................................19
Persistency ........................................................................................19
Portability ........................................................................................19
Robustness ........................................................................................19
Extensibility......................................................................................20
Security ............................................................................................20
The Java Servlet Architecture ................................................................20
GenericServlet and HttpServlet........................................................20
Summary ................................................................................................23

3 Servlet Basics 25
The Life Cycle of a Servlet ..................................................................26
The init() Method ............................................................................26
The service() Method ......................................................................26
The destroy() Method ......................................................................27
A Basic Servlet ......................................................................................27
The BasicServlet Source ..................................................................27
Dissecting the BasicServlet ..................................................................29
Where Does the BasicServlet Fit into the Servlet Framework? ......29
The Methods Overridden by the BasicServlet ................................30
Summary ................................................................................................31
vi
DEVELOPING JAVA SERVLETS, SECOND EDITION

4 Servlets and HTML 33


Retrieving Form Data in a Servlet ........................................................34
Servicing the GET and POST Requests ..........................................34
How the FormServlet Works ............................................................38
Summary ................................................................................................39

5 Servlet Sessions 41
What Is Session Tracking? ....................................................................42
Using Hidden Form Fields ....................................................................42
Working with Cookies ..........................................................................46
URL Rewriting ......................................................................................50
Session Tracking with the Servlet API ..................................................51
Summary ................................................................................................58

6 HTTP Tunneling 59
What Is HTTP Tunneling? ....................................................................60
Object Serialization................................................................................60
Creating an HTTP Tunneling Client......................................................66
Creating an HTTP Tunneling Servlet ....................................................71
A Practical HTTP Tunneling Example..................................................73
The OrderStatusApplet ....................................................................74
The OrderStatusServlet ....................................................................80
Pros and Cons of Applet-to-Servlet Communication ............................83
Summary ................................................................................................84

7 Servlets, JDBC, and Inter-Servlet Communications 85


What is the JDBC? ................................................................................86
Two- and Three-Tier Database Access Models ....................................86
JDBC Driver Types................................................................................87
Type 1: JDBC-ODBC Bridge, Plus ODBC Driver ..........................88
Type 2: Native-API, Partly Java Driver............................................88
Type 3: JDBC-Net, Pure Java Driver ..............................................89
Type 4: Native-Protocol, Pure Java Driver ......................................90
JDBC Basics ........................................................................................92
Installing and Setting Up a Type 1 Driver ......................................92
Establishing a Database Connection ................................................93
Performing the Basic SQL Commands ............................................94
A Basic JDBC Servlet ........................................................................107
A JDBC Connection Pool....................................................................112
Inter-Servlet Communications ............................................................123
Summary ..............................................................................................130
vii
CONTENTS

8 Servlets and JavaMail 131


JavaMail and Internet E-mail ..............................................................132
JavaMail Services ..........................................................................132
Preparing to Use JavaMail ..................................................................133
A JavaMail Example............................................................................133
Using JavaMail in a Servlet ................................................................137
Summary ..............................................................................................141

9 Servlet Security 143


Introduction to Security ......................................................................144
Roll Your Own ....................................................................................144
Basic Authentication ............................................................................148
Digest Authentication ..........................................................................148
Secure Sockets Layer (SSL) ................................................................149
Summary ..............................................................................................150

10 Servlets and XML 151


XML and Java......................................................................................153
Using the SAX API ........................................................................153
Using XML in a Servlet ......................................................................159
Summary ..............................................................................................162

11 Servlets and LDAP 163


A Brief Discussion of Directories ......................................................164
Attributes ........................................................................................165
Distinguished Names......................................................................165
LDAP ..................................................................................................165
JNDI ....................................................................................................166
Using JNDI to Access LDAP ..............................................................166
Installing Netscape Directory Server ............................................167
Connecting......................................................................................168
Searching the LDAP Server ..........................................................170
Adding an Object to an LDAP Server............................................174
Removing an Object ......................................................................176
Modifying Information Stored in LDAP........................................177
Accessing LDAP from a Servlet..........................................................184
Summary ..............................................................................................188

12 Servlets and Enterprise JavaBeans 189


What Are Enterprise JavaBeans? ........................................................190
EJB Terminology ................................................................................191
Installing JRun ....................................................................................191
The Enterprise JavaBean......................................................................192
Interfaces and Classes ....................................................................192
Naming Conventions ......................................................................193
viii
DEVELOPING JAVA SERVLETS, SECOND EDITION

Session Beans ......................................................................................194


Stateless Versus Stateful ................................................................194
Session Bean Interfaces and Classes..............................................195
Deployment Descriptor ..................................................................200
Client View of a Session Bean ......................................................204
Session Bean Lifecycle ..................................................................205
Entity Beans ........................................................................................206
Who Handles the Persistence? ......................................................206
Entity Bean Interfaces and Classes ................................................207
Deployment Descriptor ..................................................................215
Client View of an Entity Bean........................................................217
Entity Bean Life Cycle ..................................................................217
Deploying Your EJB to Your Application Server ................................218
Packaging the jar File ....................................................................218
Deploying the jar File ....................................................................220
Viewing Deployed Beans ..............................................................220
Servlets as EJB Clients ........................................................................220
Summary ..............................................................................................224

13 A Servlet Controller 225


What Is a Controller? ..........................................................................226
A Servlet Controller ............................................................................226
The Service Interface ..........................................................................229
A Sample Service ................................................................................230
Summary ..............................................................................................232

PART II JSP Fundamentals


14 JSP Overview and Architecture 235
What are JavaServer Pages? ................................................................236
The Components of a JavaServer Page ..............................................237
Directives........................................................................................238
Standard Actions ............................................................................240
Implicit Objects ..............................................................................241
JSP Scripting ..................................................................................242
Summary ..............................................................................................246

15 JSP Implicit Objects 247


What are Implicit Objects? ..................................................................248
The request Object ..............................................................................249
The response Object ............................................................................250
The pageContext Object ......................................................................251
The session Object ..............................................................................252
ix
CONTENTS

The application Object ........................................................................254


Testing the JSPs..............................................................................256
The out Object ....................................................................................257
The config Object ................................................................................258
The page Object ..................................................................................260
The exception Object ..........................................................................260
Summary ..............................................................................................260

16 JSP Standard Actions 261


What Are Standard Actions?................................................................262
JavaBean Standard Actions..................................................................262
The <jsp:useBean> Standard Action ..............................................262
The <jsp:setProperty> Standard Action ........................................263
The <jsp:getProperty> Standard Action ........................................264
A JSP Example Using JavaBeans ..................................................264
Other Standard Actions........................................................................268
The <jsp:param> Standard Action ................................................268
The <jsp:include> Standard Action................................................269
The <jsp:forward> Standard Action ..............................................274
The <jsp:plugin> Standard Action ................................................278
Summary ..............................................................................................279

17 Using JavaBeans and JSP Scopes 281


The Counter JavaBean ........................................................................282
page Scope ..........................................................................................283
request Scope ......................................................................................284
session Scope ......................................................................................286
application Scope ................................................................................289
Summary ..............................................................................................291

18 Handling JSP Errors 293


JSP Translation-Time Errors................................................................294
JSP Request-Time Errors ....................................................................294
Creating a JSP Error Page ..............................................................294
Using a JSP Error Page ..................................................................297
Summary ..............................................................................................300

19 Custom JSP Tag Libraries 301


JSP Customs Tags ................................................................................302
Deploying Tag Libraries ......................................................................302
Creating a Taglib Descriptor ..........................................................302
Deploying the Tag Handlers to Your Web Application ..................304
Adding a taglib Entry to Your Web Application ............................304
Adding the taglib Directive to Your JSP ........................................305
x
DEVELOPING JAVA SERVLETS, SECOND EDITION

Developing Custom JSP Tags Handlers ..............................................306


Tags Without Bodies ......................................................................306
Tags with Bodies ............................................................................311
Tags with Attributes........................................................................314
Summary ..............................................................................................317

PART III Servlet and JSP Web Applications


20 Catalog Case Study 321
Catalog Requirements..........................................................................322
Models..................................................................................................322
Shopping Cart ................................................................................325
Views....................................................................................................328
Catalog Layout ..............................................................................328
Index View......................................................................................332
Movie List View ............................................................................334
Shopping Cart View........................................................................335
Check Out View..............................................................................336
Controllers............................................................................................338
The ListMovies Service..................................................................338
The AddToCart Service ..................................................................341
The EmptyCart Service ..................................................................343
The CheckOut Service....................................................................343
Using the Online Catalog ....................................................................344
Summary ..............................................................................................345

21 An LDAP Web Client 347


Directory Requirements ......................................................................348
Models..................................................................................................348
Views....................................................................................................349
The Directory Layout ....................................................................349
Index View......................................................................................351
Directory View................................................................................352
Add View ........................................................................................354
Controllers............................................................................................356
The LDAPDirectory Service ..........................................................356
The LDAPInsert Service ................................................................358
The LDAPDelete Service ..............................................................359
Using the LDAP Application ..............................................................360
Summary ..............................................................................................361

22 A Stock Trader 363


Trader Requirements............................................................................364
Models..................................................................................................364
xi
CONTENTS

Views....................................................................................................367
Trader Layout ................................................................................367
Index View......................................................................................370
Get Quote View ..............................................................................371
Buy/Sell View ................................................................................372
Controllers............................................................................................375
The GetQuote Service ....................................................................375
The Buy Service ............................................................................377
The Sell Service..............................................................................380
Using the Trader Application ..............................................................382
Summary ..............................................................................................383

23 Wireless Application Development Using WAP 385


WAP History: Past, Present, and Future..............................................386
The Past: Handheld Device Markup Language (HDML) ..............386
Present: WAP Hits the Street..........................................................387
The Future: WAP 1.2 and Beyond ................................................387
Why WAP? ..........................................................................................389
Screen Size Considerations ............................................................389
Network Considerations ................................................................390
Bandwidth Considerations..............................................................390
WAP Architecture ................................................................................391
Emulators, Browsers, and Developer Tools ........................................392
Online Emulators............................................................................392
WinWAP Browser ..........................................................................392
Emulators and Developer Tools ....................................................394
PDA WAP Browsers ......................................................................394
Application Servers ........................................................................395
Suggested Resources............................................................................395
Summary ..............................................................................................396

24 WML/WMLScript Development 397


The Wireless Markup Language (WML) ............................................398
WML Language Basics ..................................................................398
A WML Example ................................................................................401
WMLScript ..........................................................................................405
Calling WMLScript from WML ....................................................406
Language Basics ............................................................................406
Operators ........................................................................................407
Statements ......................................................................................407
The Standard Libraries ..................................................................408
WMLScript Example......................................................................409
xii
DEVELOPING JAVA SERVLETS, SECOND EDITION

Wireless Application Developing Using Servlets................................412


Configuring Server MIME Types ..................................................412
A Quick “Hello World!” WML Servlet ........................................413
Multiple Device Support ................................................................414
Maintaining a Site in XML ............................................................414
Summary ..............................................................................................415

PART IV Appendixes
A Web Applications and Configuring the Servlet Engine 419
Web Applications ................................................................................420
The ServletContext in Relation to the Web Application................420
The Directory Structure..................................................................420
Web Application Deployment Descriptors ....................................421
Web Archive (WAR) Files ..................................................................422
Servlet Requirements ..........................................................................422
Apache Tomcat ....................................................................................422
Installing the Tomcat Server ..........................................................422
Adding the DJS Web Application ..................................................424
Building and Installing the BasicServlet........................................426
Summary ..............................................................................................427

B The javax.servlet Package 429


The javax.servlet Interfaces ................................................................430
The RequestDispatcher Interface ..................................................431
The Servlet Interface ......................................................................432
The ServletConfig Interface ..........................................................433
The ServletContext Interface..........................................................434
The ServletRequest Interface ........................................................440
The ServletResponse Interface ......................................................445
The SingleThreadModel Interface..................................................448
Classes..................................................................................................448
The GenericServlet Class ..............................................................449
The ServletInputStream Class ........................................................452
The ServletOutputStream Class ....................................................452
Exceptions............................................................................................456
The ServletException ....................................................................456
The UnavailableException ............................................................458

C The javax.servlet.http Package 461


Interfaces..............................................................................................462
The HttpServletRequest Interface ..................................................462
The HttpServletResponse Interface................................................468
The HttpSession Interface ..............................................................476
The HttpSessionBindingListener Interface ....................................479
xiii
CONTENTS

Classes..................................................................................................479
The Cookie Class............................................................................479
The HttpServlet Class ....................................................................483
The HttpSessionBindingEvent Class..............................................486
The HttpUtils Class ........................................................................487

D The javax.servlet.jsp Package 489


Interfaces..............................................................................................490
The HttpJspPage Interface..............................................................490
The JspPage Interface ....................................................................491
Classes..................................................................................................492
The JspEngineInfo Class ................................................................492
The JspFactory Class......................................................................492
The JspWriter Class........................................................................494
The PageContext Class ..................................................................502
Exceptions............................................................................................511
The JspError Exception ..................................................................511
The JspException Exception ..........................................................512

E The javax.servlet.jsp.tagext Package 513


Interfaces..............................................................................................514
The Tag Interface............................................................................514
The BodyTag Interface ..................................................................520
Classes..................................................................................................522
The BodyContent Class..................................................................522
The BodyTagSupport Class............................................................523
The TagSupport Class ....................................................................525
The TagAttributeInfo Class ............................................................528
The TagData Class..........................................................................530
The TagExtraInfo Class ..................................................................532
The TagInfo Class ..........................................................................533
The TagLibraryInfo Class ..............................................................537
The VariableInfo Class ..................................................................539

F WML (The Wireless Markup Language) 543


WML Elements....................................................................................544

G WMLScript 547
Lang Library ........................................................................................548
abort()—The abort Function ..........................................................548
abs()—The abs Function ................................................................548
characterSet()—The characterSet Function ..................................548
exit()—The exit Function ..............................................................548
float()—The float Function ............................................................548
xiv
DEVELOPING JAVA SERVLETS, SECOND EDITION

isFloat()—The isFloat Function ....................................................549


isInt()—The isInt Function ............................................................549
max()—The max Function ............................................................549
maxInt()—The maxInt Function ....................................................549
min()—The min Function ..............................................................549
minInt()—The minInt Function......................................................549
parseFloat()—The parseFloat Function..........................................549
parseInt()—The parseInt Function ................................................549
random()—The random Function ..................................................550
seed()—The seed Function ............................................................550
Float Library ........................................................................................550
ceil()—The ceil Function ..............................................................550
floor()—The floor Function ..........................................................550
int()—The int Function ..................................................................550
maxFloat()—The maxFloat Function ............................................550
minFloat()—The minFloat Function ..............................................551
pow()—The pow Function ............................................................551
round()—The round function ........................................................551
sqrt()—The sqrt Function ..............................................................551
String Library ......................................................................................551
charAt()—The charAt Function ....................................................551
compare()—The compare Function ..............................................551
elementAt()—The elementAt Function..........................................551
elements()—The elements Function ..............................................552
find()—The find Function ..............................................................552
format()—The format Function......................................................552
insertAt()—The insertAt Function ................................................552
isEmpty()—The isEmpty Function ................................................552
length()—The length Function ......................................................552
removeAt()—The removeAt Function ..........................................552
replace()—The replace Function....................................................553
replaceAt()—The replaceAt Function............................................553
squeeze()—The squeeze Function..................................................553
subString()—The subString Function ............................................553
toString()—The toString Function ................................................553
trim()—The trim Function..............................................................553
URL Library ........................................................................................553
escapeString()—The escapeString Function ..................................554
getBase()—The getBase Function..................................................554
getFragment()—The getFragment Function ..................................554
getHost()—The getHost Function ..................................................554
getParameters()—The getParameters Function..............................554
xv
CONTENTS

getPath()—The getPath Function ..................................................554


getPort()—The getPort Function....................................................555
getQuery()—The getQuery Function ............................................555
getReferer()—The getReferer Function ........................................555
getScheme()—The getScheme Function........................................555
isValid()—The isValid Function ....................................................555
loadString()—The loadString Function..........................................555
resolve()—The resolve Function....................................................555
unescapeString()—The unescapeString Function ..........................555
WMLBrowser Library ........................................................................556
getCurrentCard()—The getCurrentCard Function ........................556
getVar()—The getVar Function ......................................................556
go()—The go Function ..................................................................556
newContext()—The newContext Function ....................................556
prev()—The prev Function ............................................................556
refresh()—The refresh Function ....................................................556
setVar()—The setVar Function ......................................................556
Dialogs Library ....................................................................................557
alert()—The alert Function ............................................................557
confirm()—The confirm Function..................................................557
prompt()—The prompt Function....................................................557

Index 559
About the Authors
Lead Author
James Goodwill is the co-founder and chief architect at Virtuas Solutions, LLC., located in
Denver, Colorado. He has extensive experience in designing and architecting e-business appli-
cations. James is also the author of Pure JavaServer Pages, which provides a thorough exami-
nation of the JavaServer Pages technology. James is currently leading Virtuas’s efforts in
developing cutting edge tools designed for J2EE e-business acceleration.
You can find the source code and support for this text at the Virtuas Solutions Web site,
http://www.virtuas.com. Select the Publications link.

Contributing Author
Bryan Morgan is an experienced writer and software developer and founder of the Wireless
Developer Network (http://www.wirelessdevnet.com) in 1999. He is a respected voice in the
wireless industry, is a regular contributor to industry publications, and has been a featured
speaker at numerous events. He holds a B.S. in electrical engineering from Clemson University
and lives in Pensacola, FL with his wife Becky and beautiful daughter Emma.
Dedication
To my girls Christy, Abby, and Emma.

Acknowledgments
Before I start thanking those close to home, I need to thank the people who made this book
what it is. They are the people who took my words and molded and shaped them into some-
thing that I hope will help you become an effective Web application developer. I would like to
thank Carol Ackerman, my acquisitions editor, who answered all my questions and resolved
any issues that came up. I would especially like to thank Tiffany Taylor for her excellent edit-
ing. I would like to thank Rob Tiffany for his great technical comments and recommendations.
I would also like to thank Cynthia Fields for her excellent copy-editing. And finally, I would
like to thank Christina Smith for managing the entire project. Each and every person made this
book what it is.
On a closer note, I would first like to thank everyone at my company, Virtuas Solutions, Inc.
for their support while I was completing this text. The entire staff contributed by picking up
my assignments when my plate was too full. In particular I would like to thank those
“UNREAL” people that I worked with on a daily basis including Matthew “Deckard” Filios,
Karen “Blue Bullet” Jackson, Eric “Crazy Mary” Johnson, Jason “Cutt” Nordyke, David
“Busta” Goedecke, Mike “Ivan” Day, Gary “Monica” Goodrum, and especially Aaron “Ronin”
Bandell, for his contribution of Chapters 11 and 12.
Finally, the most important contributors to this book are my wife Christy, and our daughters
Abby and Emma. They supported me throughout the entire book, with complete understand-
ing. They listened to me complain and took care of things when I disappeared into the office.
With their support, I can do anything.
Tell Us What You Think!
As the reader of this book, you are our most important critic and commentator. We value your
opinion and want to know what we’re doing right, what we could do better, what areas you’d
like to see us publish in, and any other words of wisdom you’re willing to pass our way.
As an executive editor for Sams Publishing, I welcome your comments. You can fax, e-mail, or
write me directly to let me know what you did or didn’t like about this book—as well as what
we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book,
and that due to the high volume of mail I receive, I might not be able to reply to every
message.
When you write, please be sure to include this book’s title and author’s name as well as your
name and phone or fax number. I will carefully review your comments and share them with the
author and editors who worked on the book.
Fax: 317-581-4770
E-mail: feedback@samspublishing.com
Mail: Michael Stephens
Executive Editor
Sams Publishing
201 West 103rd Street
Indianapolis, IN 46290 USA
Introduction
Structure of This Book
Before you begin reading this book, you might want to take a look at its basic structure. This
will help you outline your reading plan, if you choose not to read it from cover to cover. This
introduction gives you an overview of what each chapter covers.

Chapter 1, “Web Applications and the Model View


Controller (MVC) Design Pattern”
Chapter 1 lays the foundation for the entire text. It introduces your to the Model View
Controller design pattern. It also introduces you to a server-side implementation of the MVC
and how both servlets and JSPs fit into this pattern

Chapter 2, “Servlet Overview and Architecture”


Chapter 2 introduces you to the Java servlet architecture. It talks about the movement to
server-side Java. It also details reasons why you should use Java servlets.

Chapter 3, “Servlet Basics”


Chapter 3 is where you begin to actually examine servlets. This chapter details the life cycle of
a servlet and shows you source code for a basic servlet.

Chapter 4, “Servlets and HTML”


Chapter 4 shows you how to link HTML forms to Java servlets and how you should retrieve
form data in a servlet.

Chapter 5, “Servlet Sessions”


Chapter 5 discusses several ways that you can maintain state while using servlets. The methods
that it discusses include hidden form fields, cookies, URL rewriting, and session tracking with
the Servlet API.

Chapter 6, “HTTP Tunneling”


Chapter 6 covers HTTP tunneling. It provides a definition of HTTP tunneling, describes object
serialization (which is required in tunneling), it describes the creation of a tunneling client and
server, and it gives a practical tunneling example. It also covers some of the pros and cons of
applet to servlet communications.
2
DEVELOPING JAVA SERVLETS

Chapter 7, “Servlets, JDBC, and Inter-Servlet


Communications”
Chapter 7 discusses how servlets can use the JDBC to interact with relational databases. It
gives a basic introduction to the JDBC and then combines the technology with servlets. It also
discusses a technique used to communicate between servlets.

Chapter 8, “Servlets and JavaMail”


Chapter 8 discusses JavaMail and how you to use it with servlets and other applications.

Chapter 9, “Servlet Security”


Chapter 9 describes security issues that you face when deploying an application to the Internet.
It covers the most popular security techniques. It also describes some of each technique’s pros
and cons.

Chapter 10, “Servlets and XML”


Chapter 10 covers the basics of Extensible Markup Language, or XML. It discusses how to use
Sun’s SAX parser. It also shows an example of how you would incorporate XML and servlets.

Chapter 11, “Servlets and LDAP”


Chapter 11 covers the Lightweight Directory Access Protocol (LDAP). It covers using JNDI to
access LDAP servers and it closes with an LDAP example integrated into a servlet.

Chapter 12, “Servlets and Enterprise JavaBeans”


Chapter 12 provides an introduction to Enterprise JavaBeans (EJB). It covers using EJBs from
an application as well as integrated into a servlet.

Chapter 13, “A Servlet Controller”


Chapter 13 shows you how to create a servlet class that acts as the Controller in the Model
View Controller design pattern.

Chapter 14, “JSP Overview and Architecture”


Chapter 14 takes a look at the basics of JSP and the components of JSPs. It shows you how to
create a JSP document and understand what is happening behind the scenes at request time. It
also discusses the process a JSP file goes through when it is first requested.
3
INTRODUCTION

Chapter 15, “JSP Implicit Objects”


Chapter 15 discusses the JSP implicit objects and how they are commonly used. It also talks
about how they are created in the JSP’s generated servlet.

Chapter 16, “Using JSP Standard Actions”


Chapter 16 covers the JSP standard actions, including how they are implemented and how you
can use them.

Chapter 17, “Using JavaBeans and JSP Scopes”


Chapter 17 covers how JSP beans are scoped. It discusses the different types of JSP scope. It
also covers how the life of a JSP bean is determined by its scope.

Chapter 18, “Handling JSP Errors”


Chapter 18 covers the types of errors that can occur in a JSP. It shows you how to handle and
respond to these errors using a JSP error page.

Chapter 19, “Custom JSP Tag Libraries”


Chapter 19 covers custom JSP tag libraries including tags with and without bodies. It also dis-
cusses how tags are packaged and deployed.

Chapter 20, “Catalog Case Study”


Chapter 20 provides an MVC case study using an online movie catalog as an example includ-
ing requirements, MVC components, and how to use the finished catalog.

Chapter 21, “An LDAP Web Client”


Chapter 21 provides an MVC case study using a LDAP client as an example including require-
ments, MVC components, and how to use the finished client.

Chapter 22, “A Stock Trader”


Chapter 22 provides an MVC case study using a stock trading application as an example
including requirements, MVC components, and how to use the finished application.
4
DEVELOPING JAVA SERVLETS

Chapter 23, “Wireless Application Development Using


WAP”
Chapter 23 introduces you to wireless application development using Java servlets and the
Wireless Application Protocol (WAP), including the wide variety of client and server tools
available to the WAP developer. It includes an example in which you create a dynamic wireless
application using servlets and WAP.

Chapter 24, “WML/WMLScript Development”


Chapter 24 illustrates how to develop dynamic wireless Web applications using Java servlets,
WML, and WMLScript.

Appendix A, “Web Applications and Configuring the


Servlet Engine”
Appendix A covers the steps involved in retrieving and configuring the Tomcat server neces-
sary to run the examples in this text.

Appendix B, “The javax.servlet Package”


Appendix B covers the classes, interfaces, and exceptions of the javax.servlet package.

Appendix C, “The javax.servlet.http Package”


Appendix C covers the classes, interfaces, and exceptions of the javax.servlet.http pack-
age.

Appendix D, “The javax.servlet.jsp Package”


Appendix D covers the classes, interfaces, and exceptions of the javax.servlet.jsp package.

Appendix E, “The javax.servlet.jsp.tagext


Package”
Appendix E covers the classes, interfaces, and exceptions of the javax.servlet.jsp.tagext
package.

Appendix F, “WML (The Wireless Markup Language)”


Appendix F provides a tag references for WML.
5
INTRODUCTION

Appendix G, “WMLScript”
Appendix G describes the libraries and functions used in WMLScript.
Exploring the Variety of Random
Documents with Different Content
Returning to the Valley, he assaulted, with his united force, the
column of Banks, annihilated an entire division of the enemy,
pursued its fugitive remnants to the Potomac, and threatened the
safety of the Federal capital. Alarmed for Washington, Mr. Lincoln
halted McDowell in his plans of coöperation with McClellan, and for
weeks the efforts of the Federal Government were addressed to the
paramount purpose of “catching Jackson.” Eluding the enemy’s
combinations, Jackson turned upon his pursuers, again defeated
Fremont at Cross Keys, and immediately crossing the Shenandoah,
secured his rear, and destroyed the advance of Shields within sight
of its powerless confederate. Resuming the retreat, Jackson paused
at Weyer’s Cave, and awaited the summons of his superiors to enact
his thrilling rôle in the absorbing drama at Richmond. Within the
short period of seventy days, Jackson achieved at Kernstown,
McDowell’s, Front Royal, Winchester, Strasburg, Harrisonburg, Cross
Keys, and Port Republic, eight tactical victories, besides innumerable
successful combats. But he had done more. He had wrought the
incomparable strategic achievement of neutralizing sixty thousand
men with fifteen thousand; he had recalled McDowell, when, with
outstretched arm, McClellan had already planted his right wing,
under Porter, at Hanover Court-house, to receive the advance of the
coöperating column from Fredericksburg.
Meanwhile the lines of Richmond had been the scene of no incident
of special interest until the battle of “Seven Pines,” on the 31st of
May. After his arrival upon the Chickahominy, McClellan had been
steadily fortifying his lines, and wherever an advance was
practicable, preparing approaches to Richmond. His line, extending
over a space of several miles, was accurately described by the
course of the Chickahominy, from the village of Mechanicsville, five
miles north of Richmond, to a point about four miles from the city, in
an easterly direction. Having partially executed his design of bridging
the Chickahominy, McClellan had crossed that stream, and in the last
days of May, his left wing was fortified near the locality designated
the “Seven Pines.” This initiative demonstration by McClellan, which
placed his army astride a variable stream, was sufficiently
provocative of the enterprise of his antagonist. To increase the peril
of the isolated wing of the Federal army, a thunder-storm, occurring
on the night of the 29th of May, had so swollen the Chickahominy as
to render difficult the accession of reënforcements from the main
body.
Such was the situation which invited the Confederate commander to
undertake the destruction of the exposed column of his adversary—a
movement which, if successful, might have resulted in the rout of
the entire left wing of the enemy, opening a way to his rear, and
securing his utter overthrow. Seven Pines was an action, in which
the color of victory was entirely with the Confederates, but it was
the least fruitful engagement fought by the two armies in Virginia.
There was no engagement of the war in which the valor of the
Confederate soldier was more splendidly illustrated, though happily
that quality then did not require so conspicuous a test. However able
in design, it was in execution a signal failure—a series of loose,
indefinite and disjointed movements, wanting in coöperation, and
apparently in able executive management.
President Davis, in company with General Lee, was present during
most of the engagement. Frequently under fire, and in consultation
with his generals in exposed positions, he was conspicuous chiefly
by his efforts to animate the troops, and his presence was greeted
with evidences of the enthusiasm and confidence which it inspired.
The battle of “Seven Pines,” in itself barren of influence upon the
decision of the campaign, was nevertheless attended by an incident
—the painful and disabling wound received by General Johnston, in
all probability decisive of the future history of the Army of Northern
Virginia. Leading to an immediate and positive change of policy, it is
hardly a bold declaration that this incident determined the future of
the war in Virginia.
A disposition has been freely indulged to influence the sentence of
history, by placing President Davis and General Johnston in a sort of
antithetical juxtaposition, as exponents of different theories as to the
proper conduct of the war by the South. In view of the failure of the
Confederacy, it has been ingeniously contended that the result
vindicated the wisdom of General Johnston’s views. But besides its
evident unfairness to Mr. Davis, no criticism could be founded less
upon the intrinsic merits of the case. Overzealous and intemperate
partisans generally evince aptitude in the exaggeration of minor
differences between the leaders, whose interests they profess to
have at heart. Such results are not unfrequent in the lives of
eminent public men. In the case of General Beauregard, the
unhappy effects of officious intermeddling and misrepresentation,
from such sources, between the President and that distinguished
officer, are especially notable.
But the assumption that events have indicated the wisdom of
General Johnston’s views, in their declared antagonism to those of
Mr. Davis, is altogether unsustained. The immediate results of a
change of commanders, and a consequent inauguration of a
different policy[55]—a policy in accordance with Mr. Davis’ own views,
may, with far more reason, be alleged in support of a contrary
theory. The vigorous and aggressive policy adopted and executed by
Lee not only accorded with the wishes of the President, but fulfilled
the long-deferred popular expectation, and agreeably disappointed
the public in Lee’s capacity. For despite the general disappointment
at the absence of decisive achievements by the Army of Northern
Virginia, General Johnston commanded far more of public
confidence, than did General Lee at the period of the latter’s
accession to command.
Nothing could have been more disadvantageous to Lee, than the
contrast so freely indicated between himself and other officers.
Johnston was criticised merely because of the absence of brilliant
and decisive achievements. Lee was assumed to have proven his
incompetency by egregious failure. He was ridiculed as a closet
general. His campaigns were said to exist only on paper—to consist
of slow methodical tactics, and incessant industry with the spade,
and he was pronounced totally deficient in aggressive qualities. A
prominent Richmond editor, criticising his North-western Virginia
campaign, asserted that the unvarying intelligence from Lee was
that he was “hopelessly stuck in the mud,” and an officer was heard
to compare him to a terrapin, needing the application of a hot coal
to his back to compel him to action. But with the lapse of a fortnight
that army, which received the intelligence of Lee’s appointment to
command with misgiving and distrust, began to experience renewed
life and hope. It was not the few additional brigades given to that
army which so soon started it upon its irresistible career of victory. A
mighty hand projected its impetus, and directed its magnificent valor
against those miles of intrenchments which it had seen grow more
and more formidable, itself meanwhile an inactive spectator.
Lee found the army within sight of Richmond; he lifted it from the
mud of the Chickahominy, defeated an enemy intrenched and in
superior force; pursued the panting and disheartened fugitives to the
shelter of their shipping; defeated a second army—then both
together—within hearing of the Federal capital; fought an indecisive
battle upon the enemy’s soil, and reëstablished the Confederate line
upon the frontier. Is it a matter of wonder that the President, the
army, and the people recognized the significance of these results,
and applauded the substitution of the new system and the new
status for the old? A better explanation of so pronounced a contrast
is needed than that the “prejudice” or “injustice” of Davis withheld
from Johnston, five or even ten thousand men, which he gave to
Lee.
Yet there could be no hypothesis more presumptuous, in view of the
abundant testimony of competent military judgment, and none more
palpably untenable, than that which would deny greatness as a
soldier to Johnston. As a consummate master of strategy, in that
sense which contemplates the movements of heavy masses, and
looks to grand ultimate results, Johnston has probably few equals.
His sagacity in the divination of an enemy’s designs is remarkable;
and if he be considered as having marked deficiencies, they must be
counted as a lack of Jackson’s audacity, of Lee’s confident calculation
and executive perfection. The South regards Lee as beyond criticism.
Jefferson Davis is accustomed to say “the world has rarely produced
a man to be compared with Lee.” Yet in mere intellectuality, it is at
least questionable whether Johnston had his superior among the
Southern leaders.
But it often happens that qualities, however great, are not those
which the occasion demands. That marvelous union of qualities in
Lee, which has placed him almost above parallel, probably made him
alone adequate to the hazardous posture of affairs at Richmond in
the summer of 1862. The result, at least, made evident to the world,
the wisdom of the President, in that choice, which was at first
declared the undeserved reward of an incompetent favorite.
Whatever may be alleged to the contrary, President Davis at all
times, to the full extent of his power, aided General Johnston in the
consummation of his designs. To assert that, upon any occasion, he
either interposed obstacles to Johnston’s success, or denied him any
means in his power to confer, is to question that personal fidelity of
Jefferson Davis, which his bitterest enemy should be ashamed to
deny. Few Southern men, at least, have yet attained that measure of
malignity, or that hardihood of mendacity.
General Lee was not dilatory in his preparations to gratify that
longing aspiration which the President, on his own behalf, and in the
name of the country, briefly expressed, that “something should be
done.” Lee had a carte blanche, but frequent and anxious were the
consultations between the President and himself. The world now
knows what followed those days and nights of anxious conference,
in which were weighed the chances of success, the cost of victory,
and the possibilities of defeat. The plan executed by General Lee
was one of the most hazardous ever attempted in war, but it was not
less brilliant than bold, and at least one precedent had been
furnished by the great master of the art of war at Austerlitz. Its
perils were obvious, but the sublime confidence of Lee in the
success of his combinations went far to secure its own justification.
During the week of engagements which followed, the President was
constantly with the army and fully advised of its movements.[56] The
cordial recognition of this advisory relation between himself and Lee,
is indicated by the natural pride, and becoming sense of justice, with
which the latter, in the report of his operations against McClellan,
mentions the approving presence of the President, during the
execution of his plans. This noble harmony between Davis and Lee,
equally creditable to each, was never interrupted by one single
moment of discord. It was never marred by dictation on one side, or
complaint on the other. Unlike other commanders, Lee never
complained of want of means, or of opportunity for the execution of
his plans. Satisfied that the Government was extending all the aid in
its power, he used, to the best advantage, the means at hand and
created his opportunities. Lee never charged the President with
improper interference with the army, but freely counseled with his
constitutional commander-in-chief, whom he knew to be worthy of
the trust conferred by the country in the control of its armies.
President Davis fully comprehended and respected the jealous
functions of military command, and in the exercise of that trust no
one would have more quickly resented unauthorized official
interference. A soldier himself, he recognized freedom of action as
the privilege of the commander; as a statesman, he rendered that
cordial coöperation, which is the duty of government.
When Lee had driven McClellan from his position along the
Chickahominy, he had raised the siege of Richmond. The retreat of
McClellan to the James River, conducted with such admirable skill,
and aided by good fortune, placed the Federal army in a position
where, secure itself, another offensive movement against the
Confederate capital might, in time, be undertaken. Confederate
strategy, however, soon relieved Richmond from the apprehension of
attack, and in less than two months from the termination of the
pursuit of McClellan, Lee, by a series of masterly strokes, demolished
the armies under Pope, united for the defense of Washington, and
was preparing an invasion of Maryland.
An almost magical change in the fortunes of the Confederacy was
wrought by these active and brilliant operations, embracing so short
a period, and marked by results of such magnitude.
Not only were the two main armies of the enemy defeated, but the
entire Federal campaign in the East had been entirely disconcerted.
Richmond was saved, Washington menaced, and McClellan forced
back to the initial point of his campaign. Western Virginia, the
Carolina coast, and other localities, for months past in Federal
occupation, were almost divested of troops to swell the hosts
gathering for the rescue of Washington, and to meet the dreaded
advance, northward, of Lee’s invincible columns. From the heart of
Virginia the cloud of war was again lifted to the Potomac frontier;
the munificent harvests of the valley counties, of Fauquier, Loudon,
and the fertile contiguous territory, were again in Confederate
possession, and a numerous and victorious army was now anxious
to be led across the Rubicon of the warring sections.
From harrowing apprehension, from vague dread of indefinable but
imminent peril, the South was transported to the highest round of
confident expectation. The North, which, in the last days of June,
eagerly awaited intelligence of McClellan’s capture of Richmond, now
regarded its own capital as doomed, and did not permit itself to
breathe freely until McClellan announced the safety of Pennsylvania,
when Lee had retired to Virginia.
The inducements which invited a movement of the Confederate
forces across the Potomac were manifold. Whatever judgment the
result may now suggest, the invasion of Maryland was alike dictated
by sound military policy and justified by those moral considerations
which are ever weighty in war. The overwhelming defeat of Pope
more than realized the hope of President Davis and General Lee,
when the strategic design of a movement northward was put in
execution, by which was sought the double purpose of withdrawing
McClellan from James River and effectually checking the advance of
Pope. The successive and decisive defeats of Pope offered the
prospect of an offensive by which the splendid successes of the
campaign might be crowned with even more valuable achievements.
Demoralized, disheartened, in every way disqualified for effectual
resistance, the remnants of the armies which Lee had beaten, each
in succession, and then combined, would be an easy prey to his
victorious legions, could they be brought to a decisive field
engagement. There yet remained time, before the end of the season
of active operations, for crushing blows at the enemy, which would
finish the work thus far triumphantly successful.
To inflict still greater damage upon the enemy—to so occupy him
upon the frontier as to prevent another demonstration against
Richmond during the present year—to indicate friendship and
sympathy for the oppressed people of Maryland—to derive such aid
from them as their condition would enable them to extend, were the
potent inducements inviting the approbation of the Confederate
authorities to a movement across the Potomac. President Davis was
pledged to an invasion of the enemy’s country whenever it should
prove practicable. Now, if ever, that policy was to be initiated.
Hitherto the enemy’s power, not the will of the Confederate
Government, had prevented. Now that power was shattered. The
mighty fabric trembled to its base, and who would now venture to
estimate the consequences of a brilliant victory by Lee, on Maryland
soil, in September, 1862? What supporter of the Union can now
dwell, without a shudder, upon the imagination, even, of a
repetition, at Antietam, of the story of the Chickahominy, or Second
Manassas?
The climax of the Maryland campaign was the battle of Antietam—a
drawn battle, but followed by the early withdrawal of the
Confederate army into Virginia. It is unnecessary to dwell upon the
causes conspiring to give this portion of the campaign many of the
features of failure. With a force greatly reduced by the straggling of
his weary and exhausted troops, Lee was unable to administer the
crushing blow which he had hoped to deliver.[57] As a consequence,
the people of Maryland, of whom a large majority were thoroughly
patriotic and warm in their Southern sympathies, were not
encouraged to make that effective demonstration which would
inevitably have followed a defeat of McClellan.
Nevertheless, there was some compensation in the terrible
punishment inflicted upon the enemy at Antietam; and there was the
heightened prestige, so greatly valued by the South at this period, in
the eyes of Europe, arising from the temper and capacity of the
weaker combatant to undertake so bold an enterprise. In the
tangible evidences of success afforded by the capture of Harper’s
Ferry, with its numerous garrison supplies of arms and military
stores, was seen additional compensation for the abandonment of
the scheme of invasion.
An interval of repose was permitted the Army of Northern Virginia,
after its return from Maryland, in its encampments near Winchester,
during which it was actively strengthened and recruited to the point
of adequate preparation for expected demonstrations of the enemy.
The operations of the Western army, in many respects, were a
brilliant counterpart to the campaign in Virginia, though lacking its
brilliant fruits. We have mentioned the circumstance which placed
General Braxton Bragg in command of the Western army, after its
successful evacuation of Corinth. General Bragg was equally high in
the confidence of the President and the Southern people. Greatly
distinguished by his services in Mexico, his skillful handling, at
Shiloh, of the magnificent corps of troops, which his discipline had
made a model of efficiency, more than confirmed his Mexican fame.
Space does not permit us to follow, in detail, the execution of the
able and comprehensive strategy, by which General Bragg relieved
large sections of Tennessee and Alabama from the presence of the
enemy, penetrated the heart of Kentucky, maintained an active
offensive during the summer, and transferred the seat of war to the
Federal frontier. A part of these operations was the hurried retreat of
Buell’s immense army, from its posts in Alabama and Tennessee, for
the defense of Louisville and Cincinnati; large captures of prisoners,
horses, arms and military stores; and the brilliant progress and
successive victories of Kirby Smith and Morgan. For weeks the
situation in Kentucky seemed to promise the unqualified success of
the entire Western campaign. There was, indeed, reasonable hope
of a permanent occupation of the larger portion of Kentucky and
Tennessee by the Confederate forces.
But the battle of Perryville—an engagement not unlike Antietam in
its doubtful claim as a Federal victory—was followed by the retreat
of General Bragg, which was executed with skill, and with results
going far to relieve the disappointment of the popular hope of a
permanent occupation of Kentucky. Buell, on his arrival at Louisville,
whither he had retreated, received heavy reënforcements, which
greatly increased his already superior numbers; and Perryville, a
battle which General Bragg fought, rather to secure his retreat than
with the expectation of a decisive victory, would have been an
overwhelming Confederate success, had Bragg been sufficiently
strong to follow up his advantage.
No Confederate commander, save Lee and Jackson, was ever able to
present a claim of a successful campaign so well grounded as the
Kentucky campaign of Bragg. With a force of forty thousand men, he
killed, wounded, and captured more than twenty thousand of the
enemy; took thirty pieces of artillery, thousands of small arms; a
large supply of wagons, harness, and horses; and an immense
amount of subsistence, ample not only for the support of his own
army, but of other forces of the Confederacy. During the succeeding
autumn and winter, Bragg’s army was conspicuous for its superior
organization, admirable condition and tone; was abundantly supplied
with food and clothing, and in larger numbers than when it started
upon its campaign in August. Moreover, General Bragg redeemed
North Alabama and Middle Tennessee, and recovered possession of
Cumberland Gap, the doorway, through the mountains, to Knoxville
and the Virginia and Tennessee Railroad—the main avenue from
Richmond to the heart of the Confederacy. Evincing his
determination to hold the recovered territory, General Bragg, within
a month from his return from Kentucky, was confronting the
principal army of the enemy, in the West, before Nashville.
Incidental to the movement of Bragg into Kentucky, and constituting
a part of the programme, attempted upon the large theatre of the
Western campaign, were the repulse of the first attack of the enemy
upon Vicksburg, the partial failure of General Breckinridge’s
expedition to Baton Rouge, and the serious reverse sustained by Van
Dorn at Corinth. In connection with the more important
demonstration into Kentucky, these incidents of the Western
campaign may be briefly aggregated as the recovery of the country
between Nashville and Chattanooga, and the important advantage of
a secure occupation of Vicksburg and Port Hudson, thus closing the
Mississippi to the enemy for two hundred miles.
Subsequent operations in Virginia, at the close of 1862, were entirely
favorable to the Confederacy. While the two armies were confronting
each other, with the imminent prospect of active and important
operations, General McClellan was relieved, and one of his corps
commanders, General Burnside, assigned to the command of the
Federal army of the Potomac. As is now universally acknowledged,
General McClellan was sacrificed to the clamor of a political faction.
By this act Mr. Lincoln became responsible for much of the ill-fortune
which awaited the Federal arms in Virginia.
Perhaps among his countrymen, a Southern tribute to General
McClellan may constitute but feeble praise. He was unquestionably
the ablest and most accomplished soldier exhibited by the war on
the Northern side. “Had there been no McClellan,” General Meade is
reported to have said, “there would have been no Grant.” In
retirement, if not exile, General McClellan saw the armies which his
genius created, achieve undeserved distinction for men, his inferiors
in all that constitutes true generalship. He saw the feeble and
wasted remnant of an army, with which he had grappled in the day
of its glory and strength, surrender to a multitudinous host, doubly
as large as the army with which he had given Lee his first check at
Antietam. A true soldier, McClellan was also a true gentleman, an
enemy whose talents the South respects none the less, because he
did not wantonly ravage its homes, nor make war upon the helpless,
the aged, and infirm. President Davis, who, while Federal Secretary
of War, conferred upon McClellan a special distinction, held his
genius and attainments in high estimation. He received the
intelligence of his removal with profound satisfaction.
The North was not required to wait long for a competent test of the
new commander’s capacity. Foiled and deceived by Lee, in a series
of maneuvres, the results of which made him only less ridiculous
than the gasconading Pope among Federal commanders, Burnside
finally assailed Lee, on the 13th December, at Fredericksburg. The
result was a bloody slaughter, unequaled in previous annals of the
war, an overwhelming repulse, and a demoralized retreat across the
Rappahannock.
The Western campaign terminated with the battle of Murfreesboro’.
The Federal commander, Rosecrans, the successor of Buell,
advanced from Nashville to drive Bragg from his position. A brilliant
and vigorous attack by Bragg, on the 31st December, routed an
entire wing of the Federal army; on the second day the action was
more favorable to Rosecrans, who had retreated, after his reverse on
the first day, to stronger positions. Receiving information that the
enemy was strongly reënforcing, General Bragg fell back to
Tullahoma, a position more favorable for strategic and defensive
purposes.
The transfer, after the battle of Shiloh, of the troops of Price and Van
Dorn to the army east of the Mississippi, had almost divested the
Trans-Mississippi Department of interest in the public mind. After Elk
Horn, there was but one considerable engagement, in 1862, west of
the Mississippi. This was the battle of Prairie Grove, a fruitless
victory, won by General Hindman, about the middle of December.
The country north of the Arkansas River continued to be nominally
held by the Federal forces.
Thus, in nearly every quarter, the second year of the war terminated
with events favorable to the prospects of Southern independence.
Though the territorial jurisdiction of the Confederacy was contracted,
the world was not far from regarding the task of subjugation as
already a demonstrated and hopeless failure. All the invasive
campaigns of the enemy, save the first shock of his overwhelming
onsets against weak and untenable posts, in the winter and early
spring, had been brought to grief, and nowhere had he maintained
himself away from his water facilities. An unexampled prestige
among nations now belonged to the infant power, which had carried
its arms from the Tennessee to the Ohio, had achieved a week of
victories before its own capital, and carried the war back to its
threshold. After such achievements the Southern Confederacy rightly
claimed from those powers which have assumed to be the arbiters
of international right an instant recognition upon the list of declared
and established nationalities.
In our brief and cursory glance at military operations, we have
omitted to mention the action of the Government designed to
promote the successful prosecution of the war. This action is mainly
comprehended by the various suggestions of the President’s
messages to Congress. These recommendations related chiefly to
measures having in view the increased efficiency of the service. He
invited the attention of Congress, especially, to the necessity of
measures securing the proper execution of the conscription law, and
the consolidation of companies, battalions and regiments, when so
reduced in strength as to impair that uniformity of organization,
which was necessary in the army. Legislation was urged, having in
view a better control of military transportation on the railroads, and
the improvement of their defective condition. The President also
recommended various propositions relating to organization of the
army, and an extension of the provisions of the conscription law,
embracing persons between the ages of thirty-five and forty-five
years.
About the middle of December President Davis visited the camps of
the Western Department, spending several weeks in obtaining
information as to the condition and wants of that section of the
Confederacy, and devising expedients for a more successful defense
in a quarter where the Confederate cause was always seriously
menaced. His presence was highly beneficial in allaying popular
distrust, founded upon the supposition that Virginia and the Atlantic
region engrossed the attention of the Government to the exclusion
of concern for the West and the Mississippi Valley. When the
President returned to Richmond, there were signs of popular
animation in the South-west, which justified a more confident hope
of the cause, than the South was permitted to indulge at any other
period of the struggle.
An incident of this visit was the address of the President before the
Mississippi Legislature. The warm affection of Mr. Davis for
Mississippi is more than reciprocated by the noble and chivalrous
people of that State. He was always proud of the confidence reposed
in him by such a community, and Mississippi can never abate her
affection for one who so illustrated her name in the council chamber
and upon the field of battle. In this address he alluded, with much
tenderness, to this reciprocal attachment, declaring, that though “as
President of the Confederate States, he had determined to make no
distinction between the various parts of the country—to know no
separate State—yet his heart always beat more warmly for
Mississippi, and he had looked on Mississippi soldiers with a pride
and emotion, such as no others inspired.”
Declaring that his course had been dictated by the sincere purpose
of promoting the cause of independence, he admonished the
country to prepare for a desperate contest, with a power armed for
the purposes of conquest and subjugation. He characterized severely
the conduct of the war by the North. Reviewing its progress, and
recounting the immense disadvantages, with which the South
contended, he maintained that the South should congratulate itself
on its achievements, and not complain that more had not been
accomplished. The conscription law was explained and defended as
to many of its features not clearly understood by the people. We
give an extract from Mr. Davis’ remarks as to the Confederate
conscription, a subject of vast misrepresentation during the war, and
of much ignorant censure since:
“I am told that this act has excited some discontentment, and that it
has provoked censure far more severe, I believe, than it deserves. It
has been said that it exempts the rich from military service, and
forces the poor to fight the battles of the country. The poor do,
indeed, fight the battles of the country. It is the poor who save
nations and make revolutions. But is it true that, in this war, the men
of property have shrunk from the ordeal of the battle-field? Look
through the army; cast your eyes upon the maimed heroes of the
war whom you meet in your streets and in the hospitals; remember
the martyrs of the conflict; and I am sure you will find among them
more than a fair proportion drawn from the ranks of men of
property. The object of that portion of the act which exempts those
having charge of twenty or more negroes, was not to draw any
distinction of classes, but simply to provide a force, in the nature of
a police force, sufficient to keep our negroes in control. This was the
sole object of the clause. Had it been otherwise, it would never have
received my signature. As I have already said, we have no cause to
complain of the rich. All our people have done well; and, while the
poor have nobly discharged their duties, most of the wealthiest and
most distinguished families of the South have representatives in the
ranks. I take, as an example, the case of one of your own
representatives in Congress, who was nominated for Congress and
elected, but still did a sentinel’s duty until Congress met. Nor is this a
solitary instance, for men of largest fortune in Mississippi are now
serving in the ranks.”
The President strongly and eloquently recommended the provision
by the Legislature for the families of the absent soldiers of
Mississippi. Said he: “Let this provision be made for the objects of
his affection and his solicitude, and the soldier, engaged in fighting
the battles of his country, will no longer be disturbed in his slumbers
by dreams of an unprotected and neglected family at home. Let him
know that his mother Mississippi has spread her protecting mantle
over those he loves, and he will be ready to fight your battles, to
protect your honor, and in your cause to die.”
The address concluded with an earnest appeal for unrelaxed
exertion, and the declaration that, “in all respects, moral as well as
physical, the Confederacy was better prepared than it was a year
previous”—a declaration verified not less by the favorable situation
than by the evident apprehension of the North and the expectations
of Europe.
CHAPTER XIV.
RESPECT OF MANKIND FOR THE SOUTH—THE
MOST PROSPEROUS PERIOD OF THE WAR—HOW
MR. DAVIS CONTRIBUTED TO THE DISTINCTION OF
THE SOUTH—FACTION SILENCED—THE EUROPEAN
ESTIMATE OF JEFFERSON DAVIS—HOW HE
DIGNIFIED THE CAUSE OF THE SOUTH—HIS STATE
PAPERS—HIS ADMINISTRATION OF CIVIL MATTERS
—THE CONTRAST BETWEEN THE TWO PRESIDENTS
—MR. DAVIS’ OBSERVANCE OF CONSTITUTIONAL
RESTRAINTS—ARBITRARY ADMINISTRATION OF
MR. LINCOLN—MR. DAVIS’ MODERATION—HE
SEEKS TO CONDUCT THE WAR UPON CIVILIZED
IDEAS—AN ENGLISH CHARACTERIZATION OF DAVIS
—COLONEL FREEMANTLE’S INTERVIEW WITH HIM
—MR. GLADSTONE’S OPINION—THE PURELY
PERSONAL AND SENTIMENTAL ADMIRATION OF
EUROPE FOR THE SOUTH—INCONSISTENT
CONDUCT OF THE EUROPEAN GREAT POWERS—
THE LONDON “TIMES” BEFORE M’CLELLAN’S
DEFEAT—THE CONFEDERACY ENTITLED TO
RECOGNITION BY EUROPE—ENGLAND’S SYMPATHY
WITH THE NORTH—DIGNIFIED ATTITUDE OF
PRESIDENT DAVIS UPON THE SUBJECT OF
RECOGNITION—HIS EARLY PREDICTION UPON THE
SUBJECT—FRANCE AND ENGLAND EXPOSED TO
INJURIOUS SUSPICIONS—TERGIVERSATIONS OF
THE PALMERSTON CABINET—THE BROAD FARCE OF
“BRITISH NEUTRALITY”—ENGLAND DECLINES TO
UNITE WITH FRANCE IN AN OFFER OF MEDIATION
BETWEEN THE AMERICAN BELLIGERENTS—
ENGLAND’S “POLICY”—SHE SOUGHT THE RUIN OF
BOTH SECTIONS OF AMERICA—CULMINATION OF
THE ANTISLAVERY POLICY OF THE NORTH—MR.
LINCOLN’S CONVERSATION WITH A KENTUCKY
MEMBER OF CONGRESS—THE WAR A “CRIME” BY
MR. LINCOLN’S OWN SHOWING—VIOLATION OF
PLEDGES AND ARBITRARY ACTS OF THE FEDERAL
GOVERNMENT—THE MASK REMOVED AFTER THE
BATTLE OF ANTIETAM—THE REAL PURPOSE OF
EMANCIPATION—MR. DAVIS’ ALLUSION TO THE
SUBJECT—INDIGNATION OF THE SOUTH AT THE
MEASURE—MILITARY OPERATIONS IN TEXAS AND
MISSISSIPPI—VICKSBURG—PORT HUDSON—LOSS
OF ARKANSAS POST—FEDERAL FLEET REPULSED AT
CHARLESTON—PREPARATIONS FOR THE CAMPAIGN
—UNITY AND CONFIDENCE OF THE SOUTH—MR.
DAVIS’ ADDRESS TO THE COUNTRY—IMPORTANT
EXTRACTS—GENERAL LEE PREPARES FOR BATTLE—
HIS CONFIDENCE—CONDITION OF HIS ARMY—
BATTLE OF CHANCELLORSVILLE—JEFFERSON
DAVIS’ TRIBUTE TO STONEWALL JACKSON.

T HERE is much justice in the sentiment that declares that there


can be magnificence even in failure. Men often turn to the
contemplation of rôles enacted in history, ending in disaster and
utter disappointment of the originating and vitalizing aspiration, with
far more of interest than has been felt in following records marked
by the palpable tokens of complete success.
It may well be doubted, whether the Confederate States of America,
even had victory crowned their prolonged struggle of superhuman
valor and unstinted sacrifice, could have commanded more of the
esteem of mankind, than will be awarded them in the years to come.
Retrospect of the most prosperous period of the fortunes of the
Confederacy—the interval between the battle of Fredericksburg,
December, 1862, and the ensuing midsummer—reveals a period in
which there was wanting no element of glory, of pride, or of hope.
Many a people, now proudly boasting an honored recognition at the
council-board of nations, might envy the fame of the meteor power
which flashed across the firmament, with a glorious radiance that
made more mournful its final extinguishment.
A notable feature of the distinction which the South, at that time
especially, commanded in the eyes of the world, was the enthusiastic
and universal tribute of mankind to the leader, whose genius, purity,
dignity, and eloquence so adorned the cause of his country. The
North sought to console its wounded national pride by accounting
for the crushing and humiliating defeats of the recent campaign, by
contrasts between the able leadership of its antagonist, and its own
imbecile administration. At the South faction was silenced, in the
presence of the wondrous results achieved in spite of its own
outcries and prophecies of failure. Demagogues, in such a season of
good fortune, ceased their charges of narrowness, of rash zealotry,
of favoritism, of incompetency, seemingly conscious, for once, of the
praise which they bestowed upon the Executive, whom they accused
of usurping all the authority of the Government, in ascribing such
results to his unaided capacity.
From Europe, in the beginning, so prejudiced against the South and
its cause, so misinformed of Southern motives, and unacquainted
with Southern history, came the tribute of disinterested eulogy, the
more to be valued, because reluctantly accorded, to the Confederacy
and its ruler. To Europe the South was now known not only through
a series of unparalleled victories; as a people who had successfully
asserted their independence for nearly two years, against such odds
as had never been seen before; as a land of valiant soldiers, of great
generals, and of large material resources. If possible, above these,
the statesmen and politicians of Europe admired the administrative
capacity, which, they declared, had given a superior model and a
new dignity to the science of statesmanship. To the educated circles
of Europe the new power was introduced by State papers, which
were declared to be models, not less of skilled political narration and
exposition, than of literary purity and excellence. Accustomed to
hear the South twitted as a people dwarfed and debased by the
demoralization of African slavery, the educated classes of England
acknowledged the surprise and delight they experienced from the
powerful and splendid vindications of the cause of the Confederacy,
in the messages of Mr. Davis. It has been truthfully remarked that
there could be no better history of the war than that contained in his
numerous state papers. They are the exhaustive summary, and
unanswerable statement of the imperishable truths which justify the
South, and overwhelm her enemies with the proof of their own acts
of wrong and violence.
Under the new light given to mankind, as to the origin, nature, and
purposes of the American Union, which Mr. Davis so lucidly
explained, Europe soon recognized his position as something else
than that of a ruler of an insurgent district. But not only as the
chosen Executive of eleven separate communities, several of which
European governments had previously recognized as sovereign; as
one who had organized great armies, maintained them in the field,
and selected leaders for their command already illustrious in the
annals of war; not for these and other features of enduring fame,
alone, was Jefferson Davis admired in Europe. The contrast between
the civil administrations of the hostile sections was viewed as,
perhaps, the chiefly remarkable phase of the struggle.
President Lincoln, beginning the war with usurpation, had
committed, in its progress, every possible trespass upon the Federal
Constitution, and was now under the influence of a faction whose
every aim contemplated the overthrow of that instrument. President
Davis, supported by a confiding people, and an overwhelming
majority of every Southern community, ruled in strict conformity with
the laws of the land and its Constitution. In the midst of a
revolution, unexampled in magnitude, in fierceness, and
vindictiveness on the part of the enemy, and of difficulties in his own
administration, he furnished an example of courage, humanity, and
magnanimity, together with the observance of order, civil freedom,
and legal and constitutional restraints unexampled in history. In the
Confederacy, the Roman maxim, Inter arma silent leges, universally
recognized and practiced among nations, had an emphatic
repudiation, so far as concerned the exercise of power by the
executive department. Whatever may have been the exceptional
cases of unauthorized oppression or violence, there was always
redress in the judiciary department of the Government, which
continued in pure and dignified existence until the end.
The President, obeying the dictates of exalted patriotism—acting
always for the public good, if not always with unimpeachable
wisdom, at least with incorruptible integrity—made no attempt at
improper interference with Congress, nor sought to exercise undue
influence over its deliberations. The press, usually the first bulwark
of the public liberties to attract the exercise of despotism, so
trammeled at the North, was free in the South every-where; in some
instances, to the extent of licentiousness, and to the positive injury
of the cause.
In marked contrast with these exhibitions were the evidences of
coming despotism at the North. The Federal judiciary was rapidly
declining from its exalted purity, before the exactions of military
power; the Federal Congress was charged by the press with open
and notorious corruption, and was aiding Mr. Lincoln in usurpations
which startled the despotisms of Europe, and have since led to the
annihilation of the republican character of the Government.
Conspicuous, too, was the desire of Mr. Davis to conduct the war
upon a civilized and Christian basis. His forbearance, his moderation,
and stern refusal to resort to retaliation, under circumstances such
as would have justified its exercise in response to the cruelties and
outrages of the enemy, amazed the European spectator, and at times
dissatisfied his own countrymen. “Retaliation is not justice,” was his
habitual reply to urgent demands, and again and again did he
decline to “shed one drop of blood except on the field of battle.”
Never forgetting the dignity of the contest, he, up to the last
moment of his authority, redeemed the pledge which he had made
in the first weeks of the war: “to smite the smiter with manly arms,
as did our fathers before us.”
There have been few spectacles presented to the admiring gaze of
mankind, more worthily depicted than that union of capacities and
virtues in Jefferson Davis, which so eminently qualified him, in the
opinion of foreigners, for the position he held. An English writer has
eloquently sketched him as “one of the world’s foremost men,
admired as a statesman, respected as an earnest Christian, the
Washington of another generation of the same race. A resolute
statesman, calm, dignified, swaying with commanding intellect the
able men that surrounded him; eloquent as a speaker, and as a
writer giving state papers to the world which are among the finest
compositions in our time; of warm domestic affections in his inner
life, and strong religious convictions; held up by vigor of the spirit
that nerved an exhausted and feeble frame—such was the chosen
constitutional ruler of one-fourth of the American people.”
Colonel Freemantle, a distinguished English officer, whose faithful
and impartial narrative of his extended observations of the American
war, commended him to the esteem of both parties, thus concludes
an account of an interview with President Davis, in the spring of
1863:
“During my travels many people have remarked to me that Jefferson
Davis seems, in a peculiar manner, adapted to his office. His military
education at West Point rendered him intimately acquainted with the
higher officers of the army; and his post of Secretary of War, under
the old Government, brought officers of all ranks under his
immediate personal knowledge and supervision. No man could have
formed a more accurate estimate of their respective merits. This is
one of the reasons which gave the Confederates such an immense
start in the way of generals; for, having formed his opinion with
regard to appointing an officer, Mr. Davis is always most determined
to carry out his intention in spite of every obstacle. His services in
the Mexican war gave him the prestige of a brave man and a good
soldier. His services as a statesman pointed him out as the only man
who, by his unflinching determination and administrative talent, was
able to control the popular will. People speak of any misfortune
happening to him as an irreparable evil too dreadful to contemplate.”
Mr. Gladstone, a member of the British cabinet, the eminent leader
of a party in English politics, and a sympathizer with the objects of
the war as waged by the North, avowed his enthusiastic appreciation
of the lustre reflected upon the new Government, by its able
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like