100% found this document useful (3 votes)
48 views

Instant Download Developing Java Servlets 2nd Edition James Goodwill PDF All Chapter

ebook

Uploaded by

artyumlidano
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
48 views

Instant Download Developing Java Servlets 2nd Edition James Goodwill PDF All Chapter

ebook

Uploaded by

artyumlidano
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

Full download ebook at ebookgate.

com

Developing Java Servlets 2nd Edition James


Goodwill

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

Download more ebook from https://ebookgate.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Apache Jakarta Tomcat 1st Edition James Goodwill

https://ebookgate.com/product/apache-jakarta-tomcat-1st-edition-
james-goodwill/

Murach s Java Servlets and JSP 3rd Edition Edition Joel


Murach

https://ebookgate.com/product/murach-s-java-servlets-and-jsp-3rd-
edition-edition-joel-murach/

Java 2 micro edition Java in small things James White

https://ebookgate.com/product/java-2-micro-edition-java-in-small-
things-james-white/

Developing a Dream Destination James Mak

https://ebookgate.com/product/developing-a-dream-destination-
james-mak/
The Java Language Specification Third Edition James
Gosling

https://ebookgate.com/product/the-java-language-specification-
third-edition-james-gosling/

Developing Applications with Java TM and UML 1st


Edition Paul R. Reed

https://ebookgate.com/product/developing-applications-with-java-
tm-and-uml-1st-edition-paul-r-reed/

Developing Web Services with Java APIs for XML 1st


Edition Robert Hablutzel

https://ebookgate.com/product/developing-web-services-with-java-
apis-for-xml-1st-edition-robert-hablutzel/

The Java Language Specification Java SE 8 Edition James


Gosling & Bill Joy & Guy L. Steele

https://ebookgate.com/product/the-java-language-specification-
java-se-8-edition-james-gosling-bill-joy-guy-l-steele/

Java 9 Modularity Patterns and Practices for Developing


Maintainable Applications 1st Edition Sander Mak

https://ebookgate.com/product/java-9-modularity-patterns-and-
practices-for-developing-maintainable-applications-1st-edition-
sander-mak/

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.
Web Applications and the CHAPTER

1
Model View Controller (MVC)
Design Pattern

IN THIS CHAPTER
• The Model View Controller (MVC) Design
Pattern 8

• A Server-Side Implementation of the MVC 8


8
DEVELOPING JAVA SERVLETS

This chapter is the foundation for this entire text. We will look at a design pattern that lever-
ages the strengths of both servlets and Java Server Pages (JSPs) to create maintainable and
reusable Web applications: the Model View Controller (MVC). In this study we will also look
at exactly where and why both servlets and JSPs fit in this pattern. Because you have not yet
covered servlet and JSP technologies, you will have to accept some of the statements made in
this chapter. My goal for the remainder of this text is to show how and why this pattern and
these technologies work so well when developing server-side Java Web applications.

The Model View Controller (MVC) Design Pattern


The MVC originated from Smalltalk and was used to design user interfaces. In such an inter-
face, the application was made up of three classes: a Model, a View, and a Controller. Each of
these classes is defined in Table 1.1.

TABLE 1.1 The Classes of the MVC


Class Definition
Model The Model represents the data or application object. It is what is
being manipulated and presented to the user.
View The View is the screen representation of the Model. It is the object
that presents the current state of the Model.
Controller The Controller defines the way the user interface reacts to the user’s
input. The Controller is the object that manipulates the Model.

The major advantage of using the MVC design pattern is that it separates the Views and
Models. As a result, you can separate presentation from business logic, and, in turn, create or
change Views without having to change the Models or the Controller logic that manipulates the
Models. The MVC also allows Models to be represented by multiple Views.

A Server-Side Implementation of the MVC


To implement the MVC server-side pattern in Java we must combine JSPs and servlets. In this
section, we define a high-level server-side implementation of the MVC, where the Model is a
JavaBean that represents the data being transmitted or received. The Controller is a servlet that
manipulates or transmits data, and the View is a JSP that presents the results of the performed
transaction. Figure 1.1 models the steps involved in a sever-side implementation of the MVC.
Web Applications and the Model View Controller (MVC) Design Pattern
9
CHAPTER 1

Application Server 1

WEB APPLICATIONS
DESIGN PATTERN
AND THE MVC
3. EJB/
2. Servlet BEAN
(Controller)
EJB/
1. BEAN
Web Client Web 4.
Server DBMS
6.
EJB/
JSP BEAN
5.
(View)
EJB/
BEAN

FIGURE 1.1
The steps in a server-side implementation of the MVC.

These steps are as follows:


1. The Web Client makes a request to the Web Server.
2. The Web Server passes the request to the Controller Servlet.
3. The servlet performs necessary manipulations to the JavaBean/EJB Model.
4. The Controller Servlet forwards the results to the JSP View.
5. The JSP View formats the Model for display and sends the HTML results back to the
Web Server.
6. The Web Server then conveys the information back to the Web Client.
Some benefits of using a server-side implementation of the MVC include
• A clear separation of the presentation and transaction layers, which gives you the ability
to change the look and feel of an application without recompiling.
• The ability to have multiple views for multiple clients.
• The ability to have a less experienced programmer develop and maintain the user inter-
face.
• A quicker time-to-market by allowing the Controller programmers to focus only on
transactions, whereas the View programmers can focus primarily on presentation.

Servlets as MVC Controllers


We have chosen to use servlets as MVC Controllers after examining some of their strengths
and weaknesses.
10
DEVELOPING JAVA SERVLETS

Strengths of servlets as Controllers are as follows:


• Servlets have very robust server-side processing capabilities because they have access to
almost the entire Java SDK.
• The servlet architecture lends itself well to a transactional style of programming, which
is analogous to MVC Controllers.
Weaknesses of servlets as Controllers are as follows:
• Servlets require an advanced level of Java understanding that HTML programmers usu-
ally do not have.
• Servlets generally require recompilation in order to change the client presentation layer.
If we consider the previous lists, we can determine that servlets make prime candidates for
MVC Controllers, where there will be fewer changes because the presentation logic has been
abstracted.

JSPs as MVC Views


JavaServer Pages were chosen as MVC Views after a similar examination of their strengths and
weaknesses.
Strengths of JSPs as Views are as follows:
• JSPs do not require programmer recompilation after source changes.
• JSPs allow you to access Java objects that are stored in the HTTP session.
• JSPs allow you to embed Java code directly into HTML pages with scriptlets.
Weaknesses of JSPs as Views are as follows:
• As your JSP code becomes more complicated, so does your scriptlet code. This results in
confusing and difficult-to-maintain JSPs.
• If you plan to allow your HTML programmers to maintain your JSPs, which is very
common, they will require a good understanding of Java.
After examining the previous lists, we can determine that JSPs make great candidates for MVC
Views. This is because we can leverage a JSP’s access to Java objects, while conquering one of
their major weaknesses by limiting scriptlet code to presentation only.

Summary
In this chapter, we laid the foundation for the rest of this text. We looked at the MVC design
pattern and saw how we could combine servlets and JSPs to implement a server-side solution
for Web applications.
Web Applications and the Model View Controller (MVC) Design Pattern
11
CHAPTER 1

In the rest of this text we will study servlets and JSPs in the context of this model. We will 1
examine how servlets and JSPs work separately and then we will complete the text by combin-

WEB APPLICATIONS
DESIGN PATTERN
AND THE MVC
ing what we have learned into Web application case studies that implement the MVC.
PART
Servlet Fundamentals
I
IN THIS PART
2 Servlet Overview and Architecture

3 Servlet Basics

4 Servlets and HTML

5 Servlet Sessions

6 HTTP Tunneling

7 Servlets, JDBC, and Inter-Servlet Communications

8 Servlets and JavaMail

9 Servlet Security

10 Servlets and XML

11 Servlets and LDAP

12 Servlets and Enterprise JavaBeans

13 A Servlet Controller
Servlet Overview and CHAPTER

2
Architecture

IN THIS CHAPTER
• Movement to Server-Side Java 16

• Definition of a Java Servlet 16

• Practical Applications for Java Servlets 16

• Java Servlet Alternatives 17

• Reasons to Use Java Servlets 19

• The Java Servlet Architecture 20


Servlet Fundamentals
16
PART I

Movement to Server-Side Java


When the Java language was first introduced by Sun Microsystems Inc., its purpose was to
embed greater interactivity into Web pages. Java has accomplished this through the use of
applets. Applets add functionality to Web pages, but because of compatibility and bandwidth
issues, businesses have started moving to server-side Java.
Java applets are programs that are embedded directly into Web pages. When a browser loads a
Web page, which contains a reference to an applet, the applet byte-code is downloaded to the
client computer and executed by the browser. This is fine for very thin clients, but as applets
grow in size the download times become unacceptable. Applets also have compatibility prob-
lems. To run an applet you must have a compatible browser. If your customer does not have a
compatible browser, applets will not be presented with the proper content. These issues have
forced businesses to take a look at server-side Java.
Server-side Java solves the problems that applets face. When the code is being executed on the
server side, no issues arise with browser compatibility or long download times. The Java appli-
cation on the server only sends the client small packets of information, including HTML,
WML, XML, and so on, that it can understand. Java servlets are one of the options for server-
side Java development.

Definition of a Java Servlet


Servlets are generic extensions to Java-enabled servers. Their most common use is to extend
Web servers, providing a very secure, portable, and easy-to-use replacement for CGI. A servlet
is a dynamically loaded module that services requests from a Web server. It runs entirely inside
the Java Virtual Machine. Because the servlet is running on the server side, it does not depend
on browser compatibility. Figure 2.1 graphically depicts the execution of a Java servlet.

Request
Servlet
Response

Web Browser
Web Server

FIGURE 2.1
Execution of a Java Servlet.

Practical Applications for Java Servlets


Servlets can be used for any number of Web-related applications. After you start using servlets,
you will find more practical applications for them. The following are three examples that I
believe are some of the most important:
Servlet Overview and Architecture
17
CHAPTER 2

• Developing e-commerce “store fronts” will become one of the most common uses for
Java servlets. A servlet can build an online catalog based on the contents of a database. It
can then present this catalog to the customer using dynamic HTML. The customer will
choose the items to be ordered, enter the shipping and billing information, and then sub-
mit the data to a servlet. When the servlet receives the posted data, it will process the
orders and place them in the database for fulfillment. Every one of these processes can
easily be implemented using Java servlets.
• Servlets can be used to deploy Web sites that open up large legacy systems on the
Internet. Many companies have massive amounts of data stored on large mainframe sys-
tems. These businesses do not want to re-architect their systems, so they choose to pro-
2

OVERVIEW AND
vide inexpensive Web interfaces into them. Because you have the entire JDK at your

ARCHITECTURE
disposal and security provided by the Web server, you can use servlets to interface into

SERVLET
these systems using anything from TCP/IP to CORBA.
• Servlets also make very good HTTP-enabled clients to Enterprise Java Bean (EJB) appli-
cations. Using servlets as clients to EJB applications creates very secure Web applica-
tions that are able to handle very high volumes.
These are just a few examples of the power and practicality of using Java servlets. Servlets are
very viable options for most Web applications.

Java Servlet Alternatives


Some alternatives to using Java servlets are CGI, proprietary server APIs, server-side
JavaScript, or even Microsoft’s Active Server Pages. All these are viable solutions, but they
each have their own set of problems. The following sections examine some of these issues.

Common Gateway Interface


The Common Gateway Interface (CGI) is one of the most common server-side solutions used to
develop Web applications. A CGI application is an independent module that receives requests
from a Web server. The application processes the data it receives and sends it back to the server,
typically as HTML. The server then sends the data to the browser. CGI has become a standard
that is used by most of today’s Web servers. Figure 2.2 shows the interaction between the
browser, Web server, and CGI application when you implement this type of solution.
Although CGI is a widely used solution to dynamic Web development, it is also a very prob-
lematic solution. The following are some of the most common problems with CGI:
• A Web server creates a new process every time it receives a CGI request. This results in
a slower response time, because the server must create and initialize a new address space
for every process. You can also face the problem of running out of processes. Most
Servlet Fundamentals
18
PART I

servers are configured to run a limited number of processes. If the server runs out, it will
not be able to handle the client’s requests.
• Although CGI code can be implemented in almost any language, the most common plat-
form-independent language is Perl. Perl is very powerful at processing text, but it
requires the server to start a new interpreter for every request. This takes longer than
starting compiled code and still eats up available processes and resources.
• CGI runs in a completely separate process from the Web server. If a client submits a
request to a CGI program that terminates before responding to the Web server, the
browser has no way of knowing what happened. It just sits there waiting for a response
until it times out.

Request CGI1
Client New CGI1 Process
Request CGI1
Client New CGI1 Process
Request CGI1
Client New CGI1 Process
Web Server

FIGURE 2.2
The interaction of a CGI solution.

Proprietary APIs
Many Web servers include APIs that extend their functionality. The most common examples
include Netscape’s NSAPI, Microsoft’s ISAPI, and O’Reilly’s Web site API called WSAPI.
The problem with these solutions is that they are proprietary. You cannot decide to change
servers without porting your code. These APIs are also developed using languages such as C or
C++ that can contain memory leaks or core dumps that can crash the Web server.

Server-Side JavaScript
Server-side JavaScript is another solution for implementing dynamic Web sites. With this solu-
tion you embed JavaScript into precompiled HTML pages. By precompiling the Web pages
you improve performance, but the only servers that implement server-side JavaScript are
Netscape’s Enterprise, FastTrack Servers, and Microsoft’s IIS. This again ties you to a particu-
lar vendor.

Microsoft’s Active Server Pages


Microsoft has developed its own solution to the problem of dynamic Web content: Active
Server Pages (ASP). Like Server-side JavaScript, ASP is embedded into HTML pages, but it is
Servlet Overview and Architecture
19
CHAPTER 2

also similar to server-side JavaScript in that it is tied to a particular Web server: Microsoft’s
Internet Information Server. Some third-party products implement ASP, but you must purchase
them separately at additional costs.

Reasons to Use Java Servlets


Java servlets are one of the most exciting new technologies I have had the opportunity to work
with. Servlets are efficient, persistent, portable, robust, extensible, secure, and they are receiv-
ing widespread acceptance. If you use them only to replace CGI, you will have saved yourself
a lot of time and headache. Servlets solve many common problems you run into when using 2
CGI, and they prove to have a clear advantage over many of the other alternatives. The follow-

OVERVIEW AND
ARCHITECTURE
ing sections discuss some of the advantages offered by servlets.

SERVLET
Efficiency
A servlet’s initialization code is executed only the first time the Web server loads it. Once the
servlet is loaded, it is only a matter of calling a service method to handle new requests. This is
a much more efficient technique than loading a completely new executable with every request.

Persistency
Servlets can maintain state between requests. Once a servlet is loaded, it stays resident in
memory while serving incoming requests. A simple example of this is a Vector that holds a list
of categories used in an online catalog. When the servlet is initialized, it queries the database
for a list of categories and stores these categories in a Vector. As it services requests, the
servlet accesses the Vector that holds the categories instead of querying the database again.
Taking advantage of the persistent characteristics of servlets can improve your application’s
performance drastically.

Portability
Servlets are developed using Java; therefore, they are portable. This portability enables servlets
to be moved to a new operating system without changing the source. You can take code that
was compiled on a Windows NT platform and move it to a Solaris box without making any
changes.

Robustness
Because servlets are developed with access to the entire JDK, they are very powerful and
robust solutions. Java provides a well-defined exception hierarchy for error handling. It has a
garbage collector to prevent problems with memory leaks. In addition, it includes a very large
class library that includes network support, file support, database access, distributed object
components, security, and many other classes.
Servlet Fundamentals
20
PART I

Extensibility
Another advantage servlets gain by being developed in an object-oriented language such as
Java is that they can be extended and polymorphed into new objects that better suit your needs.
A good example of this is an online catalog. You might want to display the same catalog search
tool at the top of every dynamic page throughout your Web site. You definitely don’t want to
add this code to every one of your servlets. So, you implement a base servlet that builds and
initializes the search tool and then extend it to display transaction-specific responses.

Security
Servlets run on the server side, inheriting the security provided by the Web server. Servlets can
also take advantage of the Java Security Manager.

The Java Servlet Architecture


Two packages make up the servlet architecture: javax.servlet and javax.servlet.http. The
javax.servlet package contains the generic interfaces and classes that are implemented and
extended by all servlets. The java.servlet.http package contains the classes that are
extended when creating HTTP-specific servlets. An example of this is a simple servlet that
responds using HTML.
At the heart of this architecture is the interface javax.servlet.Servlet. It provides the frame-
work for all servlets. The Servlet interface defines five methods. The three most important are
the init() method, which initializes a servlet; the service() method, which receives and
responds to client requests; and the destroy() method, which performs cleanup. All servlets
must implement this interface, either directly or through inheritance. It is a very clean object-
oriented approach that makes the interface easy to extend. Figure 2.3 shows an object model
that gives a high-level view of the servlet framework.

GenericServlet and HttpServlet


The two main classes are the GenericServlet and HttpServlet classes. The HttpServlet
class is extended from GenericServlet. When you are developing your own servlets, you will
most likely be extending one of these two classes. Java servlets do not have a main() method,
which is why all servlets must implement the javax.servlet.Servlet interface. Every time a
server receives a request that points to a servlet it calls that servlet’s service() method.
If you decide to extend the GenericServlet class, you must implement the service() method.
The GenericServlet.service() method has been defined as an abstract method to force you
to follow this framework. The service() method prototype is defined as follows:
public abstract void service(ServletRequest req,
ServletResponse res) throws ServletException, IOException;s
Servlet Overview and Architecture
21
CHAPTER 2

<<Interface>> <<Interface>> <<Interface>>


javax.servlet.Servlet javax.servlet.ServletConfig java.io.Serializable

init() getInitParameter()
getServletConfig() getServletContext()
service() getInitParameterNames()
getServletInfo() getServletName()
destroy()

javax.servlet.GenericServlet

getServletContext() 2
getInitParameter()
getInitParameterNames()

OVERVIEW AND
ARCHITECTURE
log()

SERVLET
getServletInfo()
init()
getServletConfig()
service()
destroy()
getServletName()

javax.servlet.http.HttpServlet

doDelete()
doGet()
doOptions()
doPost()
doPut()
doTrace()
getLastModified()
service()

BasicServlet

FIGURE 2.3
A high-level object model of the servlet framework.

The two objects that the service() method receives are ServletRequest and
ServletResponse. The ServletRequest object holds the information that is being sent to the
servlet, whereas the ServletResponse object is where you place the data you want to send
back to the client. Figure 2.4 diagrams the flow of a GenericServlet request.
Servlet Fundamentals
22
PART I

Request GenericServlet
Client
Response service()*

Web Server

* abstract method

FIGURE 2.4
A GenericServlet Request.

Unlike the GenericServlet, when you extend HttpServlet, you don’t usually implement the
service() method. The HttpServlet class has already implemented it for you. The following
is the prototype:
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException;

When the HttpServlet.service() method is invoked, it reads the method type stored in the
request and determines which method to invoke based on this value. These are the methods
that you will want to override. If the method type is GET, the service() method will call
doGet(). If the method type is POST, it will call doPost(). Five other method types exist; they
are discussed in Chapter 3, “Servlet Basics.” All these methods have the same parameter list as
the service() method.
You might have noticed the different request/response types in the parameter list of the
HttpServlet and the GenericServlet classes. The HttpServletRequest and
HttpServletResponse classes are just extensions of ServletRequest and ServletResponse
with HTTP-specific information stored in them. Figure 2.5 diagrams the flow of a
HttpServlet request.

HttpServlet
doDelete()
Request doGet()
Client doOptions()
service()
Response doPost()
doPut()
Web Server
doTrace()

FIGURE 2.5
A HttpServlet Request.
Servlet Overview and Architecture
23
CHAPTER 2

Summary
In this chapter, you learned about Java servlet basics, practical applications for servlets, servlet
alternatives, reasons to use servlets over the alternatives, and the basic architecture of servlets.
At this point, you should have a high-level understanding of the flow of a servlet request and
what objects are involved.
In the next chapter we will look at the life cycle of a servlet. We will also create and dissect a
basic servlet.
2

OVERVIEW AND
ARCHITECTURE

SERVLET
Servlet Basics CHAPTER

3
IN THIS CHAPTER
• The Life Cycle of a Servlet 26

• A Basic Servlet 27

• Dissecting the BasicServlet 29


Servlet Fundamentals
26
PART I

The Life Cycle of a Servlet


The life cycle of a Java servlet is a very simple object-oriented design. A servlet is constructed
and initialized. It then services zero or more requests until the service that it extends shuts
down. At this point the servlet is destroyed and garbage is collected. This design explains why
servlets are such a good replacement for CGI: The servlet is loaded only once and it stays resi-
dent in memory while servicing requests.
The javax.servlet.Servlet interface declares this framework. The Servlet interface defines
the life cycle methods. These methods are the init(), the service(), and the destroy()
methods.

The init() Method


The init() method is where the servlet’s life begins. It is called by the server immediately
after the servlet is instantiated. It is called only once. In the init() method the servlet creates
and initializes the resources that it will be using while handling requests. The init() method’s
signature is defined as follows:
public void init(ServletConfig config) throws ServletException;

The init() method takes a ServletConfig object as a parameter. You should save this object
so that it can be referenced later. The most common way of doing this is to have the init()
method call super.init() passing it the ServletConfig object.
You will also notice that the init() method can throw a ServletException. If, for some rea-
son, the servlet cannot initialize the resources necessary to handle requests, the init() method
should throw a ServletException.

The service() Method


The service() method handles all requests sent by a client. It cannot start servicing requests
until the init() method has been executed. You will not usually implement this method
directly, unless you extend the GenericServlet abstract class.
The most common implementation of the service() method is in the HttpServlet class.
The HttpServlet class implements the Servlet interface by extending GenericServlet. Its
service() method supports standard HTTP/1.1 requests by determining the request type and
calling the appropriate method. The signature of the service() method is shown below.
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException;
Servlet Basics
27
CHAPTER 3

The service() method implements a request and response paradigm. The ServletRequest
object contains information about the service request, encapsulating information provided by
the client. The ServletResponse object contains the information returned to the client.

The destroy() Method


This method signifies the end of a servlet’s life. When a service is being shut down it calls the
servlet’s destroy() method. This is where any resources that were created in the init()
method should be cleaned up. If you have an open database connection, you should close it
here. This is also a good place to save any persistent information that will be used the next
time the servlet is loaded. The signature of destroy() is very simple, but I have displayed it
here just to complete the picture:
public void destroy();

A Basic Servlet
In this section, we are going to look at building a very basic servlet. Its purpose will be to ser-
vice a request and respond with the request method used by the client. We will take a quick
look at the servlet’s source code, the steps involved in compiling and installing the servlet, and 3
the HTML necessary to invoke the servlet. After you have the servlet compiled, you will need

SERVLET BASICS
to refer to Appendix A, “Web Applications and Configuring the Servlet Engine,” for instruc-
tions on how to configure the servlet engine, which actually runs your servlets.

The BasicServlet Source


Listing 3.1 contains the source code for this example. You can find the following source listing
on this book’s Web site. If you have the time, it is probably best to type the first few examples
yourself. This will help you become familiar with the basic parts of servlets. As you type or
browse over this listing, feel free to look up the referenced classes in Appendices A and B.

LISTING 3.1 BasicServlet.java Displays the REQUEST_METHOD used by the Client

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BasicServlet extends HttpServlet {

public void init(ServletConfig config)


throws ServletException {
Servlet Fundamentals
28
PART I

LISTING 3.1 Continued


// Always pass the ServletConfig object to the super class
super.init(config);
}

//Process the HTTP Get request


public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType(“text/html”);
PrintWriter out = response.getWriter();

out.println(“<html>”);
out.println(“<head><title>BasicServlet</title></head>”);
out.println(“<body>”);

// Prints the REQUEST_METHOD sent by the client


out.println(“Your request method was “ + request.getMethod()
+ “\n”);

out.println(“</body></html>”);
out.close();
}

//Process the HTTP Post request


public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType(“text/html”);
PrintWriter out = response.getWriter();

out.println(“<html>”);
out.println(“<head><title>BasicServlet</title></head>”);
out.println(“<body>”);

// Prints the REQUEST_METHOD sent by the client


out.println(“Your request method was “ + request.getMethod()
+ “\n”);

out.println(“</body></html>”);
out.close();
}
Servlet Basics
29
CHAPTER 3

LISTING 3.1 Continued


//Get Servlet information
public String getServletInfo() {

return “BasicServlet Information”;


}
}

Dissecting the BasicServlet


Now that you have had a chance to look over the source of the BasicServlet, let’s take a
closer look at each of its integral parts. We will examine where the servlet fits into the JSDK
framework, the methods that the servlet implements, and the objects being used by the servlet.

Where Does the BasicServlet Fit into the Servlet


Framework?
The first thing we are going to look at is where the BasicServlet fits into the servlet frame-
work. This servlet extends the HttpServlet class. The HttpServlet class is an abstract class
3

SERVLET BASICS
that simplifies writing HTTP servlets. It extends the GenericServlet class and provides the
functionality for handling the HTTP protocol-specific requests. The BasicServlet overrides
four of its inherited methods. Figure 3.1 shows where the BasicServlet fits into this hierarchy.

<<Interface>>
<<Interface>>
javax.servlet.ServletConfig
javax.servlet.Servlet <<Interface>>
java.io.Serializable

javax.servlet.GenericServlet

javax.servlet.http.HttpServlet

BasicServlet

FIGURE 3.1
The BasicServlet depicted in the Servlet Framework.
Servlet Fundamentals
30
PART I

The Methods Overridden by the BasicServlet


The following four methods are overridden by the BasicServlet:
• init()

• doGet()

• doPost()

• getServletInfo()

Let’s take a look at each of these methods in more detail.

The init() Method


The BasicServlet defines a very simple implementation of the init() method. It takes the
ServletConfig object that is passed to it and passes it to its parent’s init() method, which
stores the object for later use. The parent that actually holds on to the ServletConfig object is
the GenericServlet. The GenericServlet provides your servlet, through inheritance, with
methods to access the ServletConfig object. The code that performs this action follows:
super.init(config);

This is a very important step. If you do not do this, you must hold the ServletConfig object
yourself. We will discuss the significance of the ServletConfig object in later chapters.
You will also notice this implementation of the init() method does not create any resources.
This is why the BasicServlet does not implement a destroy() method.

The doGet() and doPost() Methods


The BasicServlet’s doGet() and doPost() methods are identical. The only difference is the
requests they service. The doGet() method handles GET requests and the doPost() method
handles POST requests.
Both of these methods receive HttpServletRequest and HttpServletResponse objects. These
objects encapsulate the request/response paradigm. The HttpServletRequest contains infor-
mation sent from the client, and the HttpServletResponse contains information that will be
sent back to the client. The first executed line of these methods follows:
response.setContentType(“text/html”);

This method sets the content type for the response. You can set this response property only
once. You must set this property before you can begin writing to a Writer or an OutputStream.
In our example, we are using a PrintWriter and setting the response type to text/html.
The next thing to do is get the PrintWriter. This is accomplished by calling the
ServletResponses’s getWriter() method. This is done in the following line of code:

PrintWriter out = response.getWriter();


Servlet Basics
31
CHAPTER 3

Now you have a reference to an object that will allow you to write HTML text that will be sent
back to the client in the HttpServletResponse object. The next few lines of code show how
this is done:
out.println(“<html>”);
out.println(“<head><title>BasicServlet</title></head>”);
out.println(“<body>”);

// Prints the REMOTE_ADDR sent by the client in the request


out.println(“Your request method was “ + request.getMethod()
+ “\n”);

out.println(“</body></html>”);
out.close();

This is a very straightforward method of sending HTML text back to the client. You simply
pass to the PrintWriter’s println() method the HTML text you want included in the
response and close the stream. The only thing that you might have a question about is the fol-
lowing few lines:
// Prints the REMOTE_ADDR sent by the client in the request
out.println(“Your request method was “ + request.getMethod()
3
+ “\n”);

SERVLET BASICS
This code takes advantage of the information sent from the client. It calls the
HttpServletRequest’s getMethod() method, which returns the HTTP method with which the
request was made. The HttpServletRequest object holds HTTP-protocol specific header
information.

The getServletInfo() Method


The getServletInfo() method is like the applet’s getAppletInfo() method. It can be used to
provide version, copyright, author, and any other information about itself.

Summary
In this chapter, we were finally able to start examining some servlet code. We looked at the life
cycle of a servlet. We also dissected a basic servlet, which gave us a view of each integral part
of a servlet.
You should now be able to create your own servlets. You should also have a basic understand-
ing of the servlet life cycle and where your servlets will fit into the Java servlet framework.
In the next chapter we will take a look at Web applications and how to leverage them to deploy
servlet applications.
Another random document with
no related content on Scribd:
— »pyydän sitä anteeksi, sillä heikkoudesta ja päähäni osuneen
iskun aiheuttamasta kivusta tuskin tiedän, mitä teen».

Joan de Tany vetääntyi hitaasti hänestä loitommalle, tarttui mitään


vastaamatta hänen käteensä ja lähti taluttamaan häntä pimeässä,
kylmässä käytävässä.

»Nyt meidän täytyy kävellä varovasti», huomautti hän vihdoin,


»sillä läheisyydessä on portaat».

Norman puristi hänen kättänsä tiukasti, kenties tiukemmin kuin


olosuhteet vaativat, ja tyttö antoi kätensä olla ohjatessaan miestä
hyvin hitaasti karkeatekoisia kiviportaita myöten alaspäin.

Norman of Torn aprikoi, oliko tyttö häneen suuttunut, ja ollen


kokematon rakkausasioissa hän sitten virkkoi kömpelösti:

»Joan de Tany.»

»Niin, Roger de Condé, mitä haluat?»

»Olet äänetön, ja pelkään sinun olevan minulle vihaisen. Sano


antavasi anteeksi menettelyni, jos se sinua loukkasi! Minulla on niin
vähä ystäviä», lisäsi hän surullisesta »ettei minun kannata menettää
sinun kaltaistasi».

»Et milloinkaan menetä Joan de Tanyn ystävyyttä», vakuutti neito.


»Olet voittanut hänen kunnioituksensa ja — ja —» Mutta hän ei
saanut sitä suustansa ja lopetti sen vuoksi heikosti — »ikuisen
kiitollisuutensa».

Mutta Norman of Torn arvasi, minkä sanan Joan olisi lausunut, jos
hän, Norman, olisi uskaltanut sallia hänen lausua sen. Hän ei
uskaltanut, sillä hänen silmissään väikkyi aina Bertrade de Montfortin
kuva; ja nyt hän näki toisen näyn, joka varmasti olisi sulkenut hänen
huulensa, jollei edellinen olisi sitä tehnyt — hän näki Tornin
henkipaton riippumassa hirsipuussa.

Aikaisemmin hän oli ainoastaan pelännyt Joan de Tanyn


rakastavan häntä; nyt hän sen tiesi, ja samalla kun hän ihmetteli,
että niin ihana olento saattoi tuntea rakkautta häntä kohtaan, hän
taaskin moitti itseään ja oli pahoillaan heidän kummankin tähden,
sillä hän ei puolestaan rakastanut tyttöä eikä voinut kuvitella niin
voimakasta rakkautta, joka olisi kestänyt sitä tietoa, että se kohdistui
Tornin paholaiseen.

Pian he saapuivat portaiden alapäähän, ja Joan de Tany talutti


häntä hapuillen, kuten heidän kajahtelevista askelistaan päättäen
tuntui, avarassa huoneessa. Ilma oli kylmä, kostea ja
homeentuoksuinen, ainoatakaan valonsädettä ei tunkeutunut tähän
maanalaiseen holviin eikä hiljaisuutta häirinnyt ainoakaan ääni.

»Tämä on linnan hautaholvi», supatti Joan, »ja täällä kerrotaan


tapahtuvan outoja seikkoja yön hiljaisina hetkinä; linnan nukkuessa
kuuluvat sen vainajat nousevan arkuistaan ja kalistelevan kuivia
luitansa.

»St! Mikä se oli?» hätäili hän, kun ihan heidän oikealta kupeeltaan
kuului kahinaa; sitten he selvästi erottivat vinkumista, ja Joan de
Tany pakeni Norman of Tornin voimakkaiden käsivarsien suojaan.

»Ei ole mitään pelkäämistä, Joan», rauhoitti häntä Norman of


Torn. »Kuolleet eivät heiluttele miekkoja, eivät liiku eivätkä vingu.
Tuuli ja rotat ovat luultavasti ainoana seuranamme täällä.»
»Minua peloittaa», supatti neito. »Jos saat tulta, niin varmasti
löydät täältä vanhan lampun, eikä sitten tunnu niin kaamealta.
Lapsena kävin usein tässä linnassa, ja seikkailuja etsiessämme
liikuimme usein näissä käytävissä, mutta aina päiväsaikaan ja valoa
muassamme.»

Norman of Torn noudatti hänen pyyntöään ja löydettyään lampun


sytytti sen. Kammio oli ihan tyhjä lukuunottamatta komeroissaan
olevia arkkuja ja joitakuita määrättyjen välimatkojen päähän
toisistaan seinään kiinnitettyjä marmoritauluja.

»Eipä niin kovin kammottava paikka sittenkään», huomautti


Norman, hiukan naurahtaen.

»Mikään paikka ei nyt näyttäisi kammottavalta», vastasi toinen


koruttomasti, »kunhan vain on valoa näyttämässä, että vierelläni
ovat Roger de Condén uljaat kasvot».

»Hiljaa, lapsi!» varoitti henkipatto. »Et tiedä, mitä puhut. Kun opit
tuntemaan minut paremmin, harmittelet sanojasi, sillä Roger de
Condé ei ole se, joksi häntä luulet. Älä senvuoksi enää hiiskahda
ainoaakaan kehuvaa sanaa, ennenkuin pääsemme pois tästä
onkalosta ja sinä olet turvassa isäsi saleissa.»

Pimeän huoneen äänien aiheuttama pelko oli vain ollut omiaan


tuomaan tytön kasvot taaskin likelle hänen kasvojaan, joten hän
tunsi Joanin kuuman, hivelevän hengityksen poskillaan, ja niin
sukeutui uusi rengas häntä neitoon kiinnittävään ketjuun.

Lampun valossa he etenivät ripeämmin ja saapuivat muutamien


minuuttien kuluttua holvikäytävän päässä olevalle matalalle ovelle.
»Tästä ovesta päästään linnan alapuolella olevaan rotkoon.
Olemme tulleet muurien ja vallikaivannon alitse. Mitä teemme nyt,
Roger, ilman ratsuja?»

»Laittaudutaan pois täältä ja niin kauaksi kuin suinkin pimeän


turvissa, ja epäilemättä keksin jonkun keinon viedäkseni sinut isäsi
linnaan», vastasi Norman of Torn.

Sammutettuaan valon, jotta se ei herättäisi linnan muureilla


astelevien vahtien huomiota, Norman of Torn työnsi auki pikku oven
ja astui raikkaaseen yö-ilmaan.

Rotko oli niin täynnä sekaisin kasvavia viiniköynnöksiä ja villejä


pensaita, että jos siellä oli joskus ollutkin polku, se oli nyt tyyten
hävinnyt; ja vain vaivoin mies raivasi itselleen tietä jalkoihin
takertuvien köynnöskasvien ja kärhien seassa. Tyttö kompuroi hänen
jäljessään ja kaatui kahdesti, ennenkuin he olivat edenneet
pariakymmentä askelta.

»Pelkään, etteivät voimani riitä», valitti hän vihdoin. »Tie on


vaivaloisempi kuin luulinkaan.»

Niinpä Norman of Torn nosti hänet väkevään syliinsä ja hoippui


pimeässä pensaikossa rotkon keskustaa kohti. Kului lähes tunti,
ennenkuin hän pääsi vähän matkan päässä olevalle maantielle; ja
koko sen ajan tytön pää nojasi hänen olkaansa, ja hiukset hipoivat
hänen poskeaan. Kerran, kun Joan nosti päätänsä puhuakseen
hänelle, kumartui hän tytön puoleen, ja pimeässä hänen huulensa
sattumalta pyyhkäisivät tytön huulia. Hän tunsi neidon hennon
vartalon vavahtavan käsivarsillaan ja hiljaisen huokauksen lähtevän
hänen huuliltaan.
Nyt he olivat maantiellä, mutta hän ei laskenut taakkaansa
maahan. Hänen silmiensä edessä väikkyi utua, ja hän olisi saattanut
pusertaa neitoa rintaansa vasten ja peittää hänen lämpöiset
huulensa suudelmillaan. Hitaasti hänen kasvonsa kallistuivat tytön
puoleen, yhä tiukemmaksi kävi hänen rautaisten lihaksiensa puristus,
mutta sitten hän ihan selvästi näki Tornin henkipaton ruumiin
roikkumassa hirsipuun poikkipienassa, ja sen juurella oli polvillaan
upeaan, kullalla ja runsailla jalokivillä koristettuun asuun puettu
nainen. Hänen kasvonsa olivat poispäin käännetyt, ja hänen kätensä
olivat ojennetut riippuvaa hahmoa kohti, joka heilui ja pyöri
kolkossa, ohuessa poikkipuussa. Hänen vartaloaan puistattivat
kauhuisen murheen pusertamat, tukahdutetut nyyhkytykset. Äkkiä
hän hoippuroi pystyyn ja kääntyi poistumaan, peittäen kasvonsa
käsillään; mutta silloin Norman näki hänen kasvonsa hetkisen — se
nainen, joka peittelemättä ja yksin suri Tornin henkipaton kuolemaa,
oli Bertrade de Montfort.

Hitaasti hänen käsivartensa höltisivät, ja hellävaroen ja


kunnioittavasti hän laski Joan de Tanyn maahan. Sillä hetkellä
Norman of Torn oli oppinut tuntemaan ystävyyden ja rakkauden sekä
rakkauden ja intohimon välisen eron.

Kuu valaisi heitä kirkkaasti, ja tyttö kääntyi silmät levällään ja


kummastuneena saattajaansa päin. Hän oli tuntenut rakkauden
rajun kutsun eikä jaksanut nyt käsittää miehen näennäistä
kylmyyttä, sillä hän ei ollut nähnyt mitään muuta kuin onnellisen
elämän noiden voimakkaiden käsivarsien syleilyssä.

»Joan», virkkoi Norman, »mieleni teki ihan äskenkin tehdä sinulle


vääryyttä. Suo minulle anteeksi. Unohda, mitä on välillämme
tapahtunut, kunnes voin tulla luoksesi, käyttäen omia värejäni,
jolloin meitä ei enää kiehdo kuutamon ja seikkailun lumous, ja
sitten» — hän pysähtyi — »ja sitten ilmaisen sinulle, kuka olen, ja
sinä saat sanoa, vieläkö haluat nimittää minua ystäväksesi —
enempää en pyydäkään.»

Hänellä ei ollut sydäntä kertoa tytölle rakastavansa ainoastaan


Bertrade de Montfortia, mutta olisi ollut tuhat kertaa parempi, jos
hän olisi sen tehnyt.

Joan oli vastaamaisillaan, kun heitä ympäröivistä varjoista


syöksähti esille kymmenkunta miestä, jotka vaativat heitä
antautumaan. Suoraan johtajaan osuva kuutamo valaisi kookasta,
jättiläismäistä miestä, jolla oli suunnattomat, törröttävät viikset —
hän oli Shandy.

Norman of Torn antoi kohotetun miekkansa painua.

»Minä tässä olen, Shandy», sanoi hän. »Pidä kielesi hiljaa


suussasi, kunnes puhelen kanssasi kahden kesken! Odota tässä,
mylady Joan! Nämä ovat ystäviä.»

Vietyään Shandyn syrjään hän sai tietää tämän uskollisen miehen


käyneen levottomaksi päällikkönsä pitkän poissaolon tähden ja
lähteneen etsimään häntä muassaan pieni sotilasosasto. He olivat
tavanneet ratsastajattoman sir Mortimerin syömässä ruohoa
maantien ohessa ja vähän matkan päässä huomanneet taistelun
merkkejä teiden risteyksessä. Sieltä he olivat löytäneet Norman of
Tornin kypärin, joka oli vahvistanut heidän pahimpia aavistuksiaan.
Läheisessä majassa asuva talonpoika oli kertonut heille kahakasta ja
opastanut heidät sille tielle, jota myöten kreivi vankeineen oli
lähtenyt.
»Ja nyt olemme tässä, mylord», lopetti roteva soturi.

»Kuinka monta teitä on?» tiedusti henkipatto.

»Yhteensä viisikymmentä, ne mukaanluettuina, jotka ovat


väijyksissä kauempana pensaikossa.»

»Anna meille ratsut ja käske kahden miehen ratsastaa


jäljessämme!» komensi päällikkö. »Ja, Shandy, lady ei saa tietää
tänä iltana ratsastavana Tornin henkipaton seurassa.»

»Hyvä, mylord.»

Pian he olivat ratsailla ja laskettivat maantietä myöten takaisin


Richard de Tanyn linnaa kohti.

Äänettömästi ihmetellen Joan de Tany silmäili näitä tuimia


sotilaita, jotka riensivät yön pimennosta näkyviin täyttämään Roger
de Condén, ranskalaisen herrasmiehen, käskyjä.

Punapää-Shandyn kookkaassa ruhossa oli jotakin tuttua; missä


hän oli aikaisemmin nähnyt tuon valtavan vartalon? Ja nyt hän
katseli tarkasti Roger de Condén olemusta. Niin; jossakin muualla
hän oli nähnyt nämä kaksi miestä yhdessä; mutta missä ja milloin?

Ja sitten hänen mieleensä johtui vielä yksi kummallinen seikka.


Roger de Condé ei osannut englanninkieltä, mutta kuitenkin hän oli
selvästi erottanut tämän miehen huulilta lähtevän englanninkielisiä
sanoja hänen puhutellessaan punapäistä jättiläistä.

Norman of Torn oli saanut takaisin kypärinsä siltä sotilaaltaan, joka


oli ottanut sen maanteiden risteyksestä, ja nyt hän ratsasti
äänettömänä kypärinsilmikko suljettuna, kuten hänen tapansa oli.
Nyt hänen ulkonäössään oli jotakin uhkaavaa, ja kun kuutamo
valaisi hänen takanaan ratsastavien, tuimien, äänettömien miesten
julmia kasvoja, puistatti Joan de Tanya vähäinen väristys.

Vähää ennen päivänkoittoa he saapuivat Richard de Tanyn linnalle,


ja vahdilta pääsi äänekäs luikkaus, kun Norman of Torn huusi:

»Avatkaa! Avatkaa mylady Joanille!»

He ratsastivat yhdessä linnanpihalle, jossa vallitsi kiihkeä hyörinä.


Kymmenet äänet syytivät kymmeniä kysymyksiä ja huutelivat uusia
odottamatta vastauksia.

Richard de Tany, hänen perheensä ja Mary de Stutevill olivat vielä


täysissä pukimissa, sillä he eivät olleet nukkuneet koko yönä. He
suorastaan kävivät käsiksi Joaniin ja Roger de Condéhen
lausuessaan huojentuneina ja riemastuneina heidät tervetulleiksi.

»Kas niin, kas niin!» hoki parooni. »Mennään sisälle. Teidän on


varmaankin hirveä nälkä, ja kaipaatte kunnollisia ruokaa ja juomaa.»

»Minä lähden ratsastamaan, mylord», torjui Norman of Torn.


»Minulla on pieni asia selvitettävänä ystäväni Buckinghamin kreivin
kanssa, ja pelkään, että se on kiireellinen.»

Joan de Tany katseli äänettömänä sivusta. Eikä hän kehoittanut


saattajaansa jäämään, kun tämä vei hänen kätensä huulilleen
jäähyväisiksi. Sitten Norman of Torn poistui ratsunsa selässä pihalta;
ja kun hänen sotilaansa lähtivät hänen jälkeensä sarastavan päivän
hämärässä valossa, tarkkaili de Tanyn tytär heitä portin lävitse, ja
silloin vaikeni hänelle salaisuus, sillä hän näki saman näyn, jonka hän
oli nähnyt muutamia päiviä aikaisemmin, kun hän oli kääntynyt
satulassaan katselemaan Tornin hirtehisten loittonevia hahmoja
heidän lähdettyään jatkamaan matkaansa hänen isänsä seurueen
pysäyttämisen jälkeen.
NELJÄSTOISTA LUKU

Joitakuita tunteja myöhemmin seurasi viisikymmentä miestä Norman


of Tornia sen linnan lähellä olevaan rotkoon, johon John de Fulm,
Buckinghamin herttua, oli sijoittanut päämajansa, samalla kun vielä
tuhat miestä väijyi synkän rakennuksen edustalla kasvavassa
metsässä.

Sekavan pensaikon suojassa he kenenkään näkemättä ryömivät


pienelle ovelle, josta Joan de Tany oli opastanut Roger de Condén
edellisenä yönä. Käytävien ja linnanalaisten holvien kautta he
saapuivat kiviportaille ja nousivat sille laudoitukseen sovitetulle
ovelle, josta pakenijat olivat päässeet livahtamaan.

Painettuaan lukon ponninta Norman of Torn astui huoneeseen


sotureiden seuratessa hänen kintereillään. He etenivät huoneesta
toiseen, mutta eivät etsinnästään huolimatta nähneet merkkiäkään
kreivistä eivätkä hänen palvelijoistaan, ja pian kävi selväksi, että
linna oli jätetty tyhjilleen.

Pihalle tultuaan he huomasivat penkillä päivää paistattavan


vanhuksen. Heidät nähtyään oli ukko vähällä kuolla säikähdyksestä,
sillä rohkeammankin miehen posket olisivat hyvin saattaneet kalveta
hänen nähdessään viidenkymmenen aseistetun miehen ilmestyvän
asumattomista saleista.

Häntä kuulustellessaan Norman of Torn sai tietää de Fulmin


lähteneen varhain aamulla ratsastamaan Doveriin, jossa prinssi
Edward silloin oleskeli. Henkipatto tiesi, että takaa-ajo olisi
hyödytöntä, mutta niin kiukuissaan hän oli tätä miestä kohtaan, että
hän komensi joukkonsa ratsaille, sijoittui jonon etunenään, samosi
Middlesexin halki, meni Thamesin ylitse Lontoon yläpuolelta ja
saapui Surreyhin myöhään saman päivän iltapuolella.

Heidän aikoessaan sinä iltana leiriytyä Kentissä, Lontoon ja


Rochesterin keskivälissä, Norman of Torn sai tietää Buckinghamin
kreivin lähettäneen saattueensa edelleen Doveriin ja pysähtyneen
vierailemaan erään kuningasmielisen paroonin vaimon luona, jonka
puoliso oli prinssi Edwardin joukoissa.

Tämän tiedon tuoja oli muuan myladyn palvelija, jolla oli kaunaa
emäntäänsä kohtaan jonkun hänelle tehdyn vääryyden tähden. Kun
hän kuuli näiden tuimien miesten etsivän de Fulmia, arveli hän
saaneensa mahdollisuuden kostaa emännälleen.

»Kuinka monta aseellista miestä on linnassa?» tiedusti Norman of


Torn.

»Tuskin kymmentä paitsi Buckinghamin kreiviä», vastasi palvelija.


»Ja sitäpaitsi voin näyttää teille sisäänpääsytien, mylord, niin että
pääsette kenenkään huomaamatta siihen huoneeseen, jossa mylady
ja kreivi ovat illallispöydässä.»

»Ota mukaasi kymmenen miestä, Shandy!» komensi Norman of


Torn.
»Käväisemme lyhyellä vierailulla katsomassa lemmenkaihoista
ystäväämme,
Buckinghamin kreiviä.»

Puoli tuntia ratsastettuaan he saapuivat linnan näkyviin. He


laskeutuivat maahan, jättivät hevosensa yhden sotilaan huostaan, ja
Norman of Torn ja Shandy etenivät yhdeksän jäljelläolevan miehen
seuraamina kavaltavan palvelijan jäljessä.

Mies opasti heidät linnan taakse, johon hän oli pensaikkoon


kätkenyt karkeatekoiset tikkaat, jotka nostettuina muuria vasten
nojalleen ulottuivat vallihaudan ylitse noin kolmen metrin korkeudella
maasta olevan ikkunan alareunaan.

»Pidä miestä täällä viimeiseksi, Shandy», käski henkipatto,


»kunnes kaikki ovat ehtineet sisälle, ja jos huomaat merkkiäkään
petoksesta, pistä miekkasi hänen vatsansa lävitse — siten on
kuolema hitaampi ja tuskallisempi!»

Niin sanottuaan Norman of Torn kapusi rohkeasti väliaikaista siltaa


myöten ja katosi ikkuna-aukkoon. Yksi toisensa jälkeen hirtehiset
menivät pienestä ikkunasta sisälle, kunnes kaikki olivat linnassa
päällikkönsä luona; Shandy ja palvelija tulivat viimeisinä.

»Opasta minut hiljaa siihen huoneeseen, jossa mylord on


illallisella, palvelija!» käski Norman of Torn. »Sinä, Shandy, sijoita
sotilaasi niin, että he suojelevat minua häiritsijöiltä!»

Minuutin tai parin verran Shandyn jälkeen tuli tikkaita myöten


salavihkaa hahmo, joka Norman of Tornin seurueineen poistuttua
pienestä huoneesta työntyi sisälle ikkunasta ja seurasi suurta
henkipattoa pimeässä käytävässä.
Kun mylady Leybourn hetkistä myöhemmin kohotti katseensa
lautasestaan, näki hän tilavan ruokasalin ovella seisovan tuiman
rauta-aseisen ritarin.

»Herra kreivi!» parkaisi hän. »Katsokaa taaksenne!»

Ja kun Buckinghamin kreivi vilkaisi taaksensa, kaatoi hän tuolin,


jolla istui, ehättäessään ponnahtamaan pystyyn, sillä Buckinghamin
kreivillä oli paha omatunto.

Tuima hahmo kohotti kättänsä pidättäväsi, kun kreivi tempaisi


miekkansa.

»Hetkinen, mylord», lausui matala ääni moitteettomalla


ranskankielellä.

»Kuka olette?» kirkaisi lady.

»Olen mylordin vanha ystävä; mutta sallikaa minun kertoa teille


pieni tarina!

»Eräässä kolkossa, vanhassa linnassa Essexissä piti muuan


mahtava englantilainen ylimys viime yönä väkisin vankinaan erään
jalon perheen kaunista tytärtä, ja kun neito halveksien torjui hänen
lähentelynsä, iski hän nyrkillään vasten tytön kauniita kasvoja ja
yritti kuristaa hänet raakalaiskourillaan. Siinä linnassa oli myöskin
halveksittu ja vainottu henkipatto, jonka päästä on luvattu palkkio ja
jonka kaulaa hamppuinen silmukka on odottanut useita vuosia. Ja
juuri tämä halpa mies ennätti ajoissa pelastamaan nuoren naisen
tämän ritariston ylevän kukan kynsistä, joka olisi tuhonnut hänen
nuoren elämänsä.
»Henkipatto tahtoi tappaa ritarin, mutta useita sotilaita riensi
ylimyksen avuksi, ja niinpä oli henkipaton pakko paeta tytön
seurassa, jotta ylivoima ei nujertaisi häntä ja tyttö siten jälleen
joutuisi rääkkääjänsä käsiin.

»Mutta tämä raaka henkipatto ei tyytynyt ainoastaan tytön


pelastamiseen, vaan tahtoi välttämättä myöskin oikeudenmukaisesti
rangaista hänen ylimyksellistä ryöstäjäänsä ja täysin määrin
toteuttaa verikoston, joka yksin pystyy sovittamaan neitoa
kohdanneen loukkauksen ja väkivallan.

»Mylady, se nuori tyttö oli Joan de Tany, ylimys oli mylord,


Buckinghamin kreivi, ja henkipatto seisoo edessänne suorittaakseen
sen tehtävän, jonka hän on vannonut tekevänsä. En garde, mylord!»

Taistelu oli lyhyt, sillä Norman of Torn oli tullut tappamaan, ja


hänen silmiensä edessä oli tuntikausia väikkynyt veripunainen utu,
kun hän vain oli ajatellut lurjuksen sormia Joan de Tanyn kauniissa
kaulassa ja tytön kasvoihin tärähtänyttä julmaa iskua.

Hän ei armahtanut, vaan hellittämättä pakotti kreivin


perääntymään huoneen nurkkaan; ja saatuaan hänet sinne, joten
hän ei voinut enää päästä mihinkään suuntaan, Norman of Torn
survaisi säilänsä niin voimakkaasti hänen saastaiseen sydämeensä,
että kärki upposi parin, kolmen sentimetrin syvyyteen hänen
takanansa olevaan tammilaudoitukseen.

Claudia Leybourn istui näkemänsä kohtauksen herättämän kauhun


jähmettämättä, ja kun Norman of Torn kiskaisi säilänsä irti vainajan
ruumiista ja pyyhki sitä lattialle levitettyihin ruohoihin, katseli emäntä
kaamean lumouksen vallassa, kun mies vetäisi tikarinsa ja piirsi sillä
merkin kuolleen ylimyksen otsaan.
»Olkaapa henkipatto tai paholainen», lausui tuima ääni heidän
takanaan, »Roger Leybourn on velvollinen olemaan ystävänne, koska
olette pelastanut hänen kotinsa kunnian».

Molemmat kääntyivät ja näkivät rauta-asuisen miehen oviaukossa,


josta
Norman of Torn oli äsken ilmestynyt.

»Roger!» kiljaisi Claudia Leybourn ja pyörtyi.

»Kuka olette?» kysyi Leybournin isäntä, puhutellen henkipattoa.

Vastaukseksi Norman of Torn osoitti kuolleen Buckinghamin kreivin


otsaa, ja siinä Roger Leybourn näki veriset kirjaimet NT.

Parooni astui eteenpäin käsi ojossa.

»Olen teille suuressa kiitollisuuden velassa; olette pelastanut


poloisen, ajattelemattoman vaimoni tämän raakalaisen kynsistä; ja
Joan de Tany on serkkuni, joten minun tulee olla kaksin kerroin
kiitollinen teille, Norman of Torn.»

Henkipatto ei ollut huomaavinaan toisen kättä.

»Ette ole velkaa minulle mitään sellaista, sir Roger, mitä ei voitaisi
maksaa kelpo illallisella; olen syönyt vain kerran
neljäänkymmeneenkahdeksaan tuntiin.»

Nyt henkipatto huusi luoksensa Shandyn ja hänen miehensä, käski


heidän edelleen olla vahdissa, mutta kielsi heitä häiritsemästä linnan
asukkaita.
Sitten hän istuutui pöytään Roger Leybournin ja hänen tajuihinsa
tulleen puolisonsa seurassa, ja heidän takanaan lattian heinillä virui
de Fulmin ruumis pienessä verilätäkössä.

Leybourn kertoi kuulleensa de Fulmin olevan hänen talossaan ja


kiiruhtaneensa kotiin, olleensa piilossa linnan läheisyydessä jo puoli
tuntia ennen Norman of Tornin saapumista odottamassa sopivaa
tilaisuutta pujahtaakseen sisälle palvelijoiden huomaamatta. Juuri
hän se oli kavunnut tikkaita myöten Shandyn jälkeen.

Henkipatto vietti sen yön Roger Leybournin linnassa ensi kerran


muistinsa aikaan mieluisena vieraana oikealla nimellään
herrasmiehen talossa.

Seuraavana päivänä hän sanoi isännälleen jäähyväiset, palasi


leiriinsä ja lähti paluumatkalle Torniin.

Kun he päivän alkaessa olla puolessa lähestyivät Thamesia likellä


Lontoota, näkivät he suuren väkijoukon, joka syyti pilkkahuutoja
pienelle seurueelle ylimyksiä ja aatelisnaisia.

Joillakuilla väkijoukosta oli aseita, ja yli voimaiseen lukumääräänsä


luottaen alkoi rahvas rohkaistua käymään väkivaltaisesti käsiksi
seurueeseen. Pientä ratsujoukkoa viskeltiin loalla, kivillä ja
lahonneilla kalikoilla, ja usein olivat heitot vähällä osua seurueen
naisiin.

Norman of Torn ei jäänyt kyselemään mitään, vaan karautti


ratsunsa sankimpaan tungokseen ja sivalteli miekkansa lappeella
oikealle ja vasemmalle. Hänen sotilaihinsa tarttui esimerkki, he
syöksyivät parvena hänen jälkeensä, kunnes koko ahdistava
roskajoukko oli ajettu Thamesiin.
Ja vilkaisemattakaan sitten taaksensa pelastamaansa seurueeseen
hän lähti jatkamaan matkaansa pohjoista kohti.

Pieni seurue istui ratsujensa selässä, ihmeissään katsellen


loittonevien pelastajiensa hahmoja. Sitten kääntyi muuan naisista
lähellään olevan ritarin puoleen, lausuen komennuksen ja käskevästi
viitaten nopeasti katoavaan joukkueeseen päin. Näin puhuteltu mies
kannusti hevostaan ja lähti ripeätä laukkaa ratsastamaan henkipaton
sotajoukon jälkeen. Hän saavutti sen muutamissa minuuteissa ja
pysähtyi Norman of Tornin viereen.

»Seis, herra ritari!» huusi ylimys. »Kuningatar haluaisi


henkilökohtaisesti kiittää teitä siitä, että niin urheasti puolustitte
häntä.»

Aina herkkänä tuntemaan tilanteen huumorin Norman of Torn


pyöräytti ratsunsa ympäri ja palasi kuningattaren lähetin mukana.

Saavuttuaan hänen majesteettinsa eteen Tornin henkipatto


kumarsi syvään satulan nuppinsa ylitse.

»Olette omituinen ritari, kun pidätte kuningattaren hengen


pelastamista niin mitättömänä seikkana, että ratsastatte edelleen
edes kääntämättä päätänne ikäänkuin vain olisitte karkoittanut
koiralauman juoksukissan kimpusta», virkkoi kuningatar.

»Paljastin miekkani tehdäkseni palveluksen naiselle, teidän


majesteettinne, enkä kuningattarelle.»

»Mitä nyt! Haluaisitko vielä vähäksyä tekoasi, jonka me kaikki


näimme? Kuningas, puolisoni, palkitsee sinua, herra ritari, jos vain
ilmoitat minulle nimesi.»
»Jos mainitsen nimeni, niin kuningas luultavasti mieluummin minut
hirttäisi», tokaisi henkipatto nauraen. »Olen Norman of Torn.»

Seurueen kaikki jäsenet katsahtivat häneen säikähtyneinä ja


hämmästyneinä, sillä kukaan heistä ei ollut koskaan nähnyt tätä
rohkeata rosvoa, jota koko Englannin aatelisto ja ylimystö pelkäsivät.

»Vähäisemmistäkin palveluksista kuin se on, jonka äsken suoritit,


on kuningas aikaisemmin armahtanut miehiä», lausui hänen
majesteettinsa. »Mutta avaa kypärinsilmikkosi! Haluaisin nähdä niin
kuuluisan rikollisen kasvot, joka kuitenkin osaa esiintyä herrasmiehen
tavoin ja kuningattarensa uskollisena suojelijana.»

»Ne, jotka ystäviäni lukuunottamatta ovat nähneet kasvoni»,


vastasi Norman of Torn rauhallisesti, »eivät ole jääneet eloon
kertoakseen, mitä ovat nähneet tämän kypärinsilmikon takaa; ja
mitä teihin tulee, madame, olen nyt vuoden aikana oppinut
pelkäämään, että teille saattaisi koitua onnettomuudeksi, jos
näkisitte Tornin paholaisen avatusta kypärin silmikosta hänen
kasvonsa». Mitään muuta virkkamatta hän käänsi ratsunsa ympäri ja
lasketti neliä takaisin pienen armeijansa luokse.

»Tuo nulikka, luo hävytön nulikka!» kiljui Englannin kuningatar


Eleanor raivoissaan.

Ja siten Tornin henkipatto ja hänen äitinsä kohtasivat toisensa


kaksikymmenvuotisen eron jälkeen ja taaskin erosivat.

Kaksi päivää myöhemmin Norman of Torn käski Punapää-Shandyn


viedä Tornin sotavoimat Essexissä olevasta leiristä takaisin Derbyyn.
Niinä päivinä, jotka he viettivät tässä rikkaassa piirissä, maanteillä
alituisesti liikkuneet, lukuisat saalistusjoukkueet olivat kuormittaneet
ylimääräiset kuormajuhdat runsaalla ja arvokkaalla saaliilla, ja tällä
kertaa saatuaan kyllikseen taistelua ja saalista miehet käänsivät
kasvonsa Torniin päin ilmeisen tyytyväisenä.

Henkipatto puhui alapäälliköilleen neuvottelukokouksessa; Tornin


vanhus istui hänen vierellään.

»Ratsastakaa lyhyitä taipaleita, Shandy! Minä saavutan teidät


huomenaamulla. Käväisen vain pikaisesti de Tanyn linnassa asialla, ja
koska viivyn siellä ainoastaan muutamia minuutteja, ehdin varmasti
seuraanne huomenna.»

»Älkää unohtako, mylord», muistutti Orja-Edwild, kookas,


keltahiuksinen, saksilainen jättiläinen, »että lähellä Tanyyn
haaraantuvaa tietä on leirissä osasto kuninkaan sotaväkeä!»

»Kierrän sen kyllin kaukaa», lupasi Norman of Torn. »Kaulastani ei


viruttaminen tuntuisi hyvältä», laski hän pilaa ja nousi ratsaille.

Viisi minuuttia sen jälkeen, kun hän oli ratsastanut lyhyttä laukkaa
maantietä pitkin leiristä, talutti espanjalainen Spizo kenenkään
huomaamatta hevosensa leiriä ympäröivään metsään, keikahti
satulaan ja lähti laskettamaan hänen jälkeensä. Leirissä kaikki olivat
ankarassa puuhassa sälyttäessään kuormia niskuroivien, pahasti
uupuneiden juhtien selkään ja satuloidessaan omia hurjia ratsujaan,
eikä kukaan pannut merkille hänen poistumistaan. Ainoastaan pieni,
tuikea vanhus tiesi hänen lähteneen sekä tunsi hänen matkansa syyn
ja määrän.

Samalla kun Roger de Condé sinä iltapäivänä päästettiin Richard


de Tanyn linnaan ja saatettiin pieneen huoneeseen, jossa hän odotti
lady Joanin tuloa, ojensi tumma-ihoinen sanansaattaja kirjeen
muutamien kilometrien päässä Tanyn eteläpuolella leirissä olevien
kuninkaan sotilaiden päällikölle.

Sanansaattajan käännyttyä ja lähdettyä ratsastamaan takaisin


samaa tietä, jota oli tullut, upseeri repäisi auki sinetin:

Hän luki:

Norman of Torn on nyt Tanyn linnassa ilman turvajoukkoa.

Heti kajahtelivat leirissä komennukset: »Aseisiin!» ja: »Ratsaille!»


Ja viiden minuutin kuluttua ratsasti sata palkkasotilasta ripeätä
laukkaa Richard de Tanyn linnaa kohti, ja heidän kapteeninsa
mielessä väikkyivät suuri palkkio, kunnia ja ylennys nyt melkein
hänen kynsissään olevan mahtavan henkipaton vangitsemisen
johdosta.

Tanyssa yhtyi kolme tietä, yksi etelästäpäin, se, jota myöten


kuninkaan
soturit nyt ratsastivat, toinen lännestä, se, joka oli tuonut Norman of
Tornin leiristä linnaan, ja kolmas, joka vei luoteiseen Cambridgen ja
Huntingdonin kautta Derbyä kohti.

Aavistamatta vihollisten nopeata lähestymistä Norman of Torn


odotti etuhuoneessa tyynesti Joan de Tanya.

Pian neito astui sisälle yllään sen ajan kuosin mukainen tiiviisti
sopiva kotipuku. Hän oli kaunis näky, ja hänet teki vielä
kauniimmaksi hillitty kiihtymys, joka nostatti veren hänen
samettihipiäisiin poskiinsa ja sai hänen rintansa kohoamaan ja
laskemaan sekä hänen sydämensä sykkimään vinhasti.
Hän salli vieraan ottaa hänen sormensa käteensä ja nostaa ne
huulilleen, ja sitten he seisoivat pitkän tuokion, äänettöminä katsoen
toisiaan silmiin.

»En osaa oikein puhua sinulle siitä, mistä olen tullut puhumaan»,
virkkoi Norman of Torn surullisesti. »Tarkoitukseni ei ole ollut tuottaa
sinulle ikävyyksiä pettämällä sinua, mutta houkutuksen olla sinun ja
sellaisten ihmisten seurassa, joita edustat, täytyy olla puolustukseni.
Minä —» Hän vaikeni. Oli helppo ilmaista tytölle, että hän oli Tornin
henkipatto, mutta jos Joan rakasti häntä, kuten hän pelkäsi, miten
voisi hän kertoa rakastavansa ainoastaan Bertrade de Montfortia?

»Sinun ei tarvitse ilmoittaa minulle mitään», keskeytti Joan de


Tany. »Olen arvannut kaikki, mistä minulle puhuisit, Norman of Torn.
Emme enää ole ‘kuutamon ja seikkailun lumoissa’ — ne ovat omat
sanasi — mutta sittenkin olen iloinen voidessani nimittää sinua
ystäväkseni.»

Viimeisen sanan vähäinen korostus osoitti, kuinka lopullinen hänen


se päätöksensä oli, että Tornin henkipatto ei voinut olla hänelle
enempää kuin ystävä.

»Niin on parasta», vastasi Norman hyvillään siitä, ettei tyttö, kuten


hän arveli, enää tuntenut rakkautta häntä kohtaan saatuaan tietää,
mikä mies hän oikein oli. »Sinun laisellesi, Joan de Tany, ei voisi
koitua mitään hyvää, jos Tornin henkipatto voisi vaatia sinulta
enemmän kuin ystävyyttä; ja sen vuoksi olen sitä mieltä, että sinun
mielenrauhasi tähden samoin kuin minunkin tähteni annamme
kaiken olla, ikäänkuin et olisi milloinkaan minua tuntenut. Kiitän
sinua siitä, ettet ole ollut minulle vihainen. Muista vain se, että
Derbyn kunnailla on miekka valmiina palvelukseesi ilman palkkiota ja
ilman palkkaa. Lupaa minulle, Joan, että jos milloinkaan sitä
tarvitset, lähetät minua noutamaan — lupaatko sen, Joan?»

»Lupaan, Norman of Torn.»

»Hyvästi!» sanoi mies, ja suudellessaan taaskin neidon kättä hän


notkisti polvensa maahan kunnioittavasti. Sitten hän nousi
poistaakseen, painaen pienen käärön tytön käteen. Heidän
katseensa osuivat vastakkain, ja sillä lyhyellä hetkellä mies näki
neidon syvissä, sinisissä silmissä ilmeen, joka sai hänen äsken
saavuttamansa mielenrauhan romahtamaan.

Ratsastaessaan kirkkaassa päivänpaisteessa luoteiseen Derbyä


kohti vievällä tiellä Norman of Torn painoi päänsä kumaraan
murheissaan, sillä hän käsitti kaksi asiaa. Toinen oli se, että tyttö,
josta hän oli äsken eronnut, rakasti häntä vieläkin ja joskus, kenties
jo huomenna, katuisi, koska oli lähettänyt hänet pois; ja toinen oli
se, ettei hän rakastanut tätä tyttöä, että hänen sydämensä oli
suljettu Bertrade de Montfortin kauniiseen rintaan.

Hän sätti itseään elukaksi, koska oli sallinut yksinäisyytensä ja


seurattaman, tyhjän sydämensä jäytävän kaihon johtaa hänet tämän
tytön elämään. Se, että hän oli äkkinäinen naisten seurassa ja
vieläkin äkkinäisempi rakkausasioissa, ei ollut hänen omissa
silmissään puolustus, ja satoja kertoja hän kirosi hulluuttaan ja
typeryyttään ja huikentelevaisuuttaan, jona hän sitä piti.

Mutta yhden seikan oli tämä onneton juttu hänelle varmasti


opettanut; se oli opettanut hänet varmasti tietämään, mitä rakkaus
oli, ja sen, että Bertrade de Montfortin huulien muisto aina tehoaisi
häneen voimakkaammin kuin maailman kaikkien muiden naisten
kiehtomisvoima. vaikka he olisivat kuinka viehättäviä ja kauniita.
Vielä toisenkin seikan, kirvelevän, hän oli siitä oppinut, nimittäin
sen, että juuri samalla tavoin, kuin Joan de Tany, vanhan ja jalon
suvun tytär, oli häneen suhtautunut, täytyisi Tornin henkipaton
odottaa kaikkien samaan luokkaan kuuluvien kelpo naisten häneen
suhtautuvan, samoin myöskin Bertrade de Montfortin, saatuaan
tietää, että Roger de Condé oli Norman of Torn.

Henkipatto oli tuskin ehtinyt kadota näkyvistä Derbyyn vievällä


tiellä, kun tyttö, joka yhäti seisoi eteläisen tornin ikkuna-aukossa,
kasvot oudon pingoittuneina ja murheellisina katsellen hänet niellyttä
tietä, näki ripeätä laukkaa ratsastavan sotilasosaston lähestyvän
Tanyn linnaa etelästä.

Ratsastajien yläpuolella liehui kuninkaan lippu ja vaistomaisesti


tyttö arvasi, ketä he tulivat etsimään hänen isänsä linnasta. Nopeasti
hän riensi portin ulommalle varustukselle, jotta juuri hän ennättäisi
vastaamaan tulijoin tulkkaukseen siellä olevien vahtisotilaiden
sijasta.

Hän oli tuskin ehtinyt ulomman portin varustuksille, ennenkuin


kuninkaan sotilaat pysähtyivät linnan edustalle.

Vastaukseksi heidän luikkaukseensa Joan de Tany tiedusti heidän


asiaansa.

»Etsimme Norman of Tornia, henkipattoa, joka nyt piileksii tässä


linnassa», vastasi upseeri.

»Täällä ei ole henkipattoja», vakuutti tyttö, »mutta jos haluatte,


voitte tulla sisälle muassanne kymmenkunta sotilasta tarkastamaan
linnaa».
Upseeri teki niin, ja hänen varmistuttuaan siitä, ettei Norman of
Tornia ollut siellä, oli kulunut tunti, ja Joan de Tany uskoi Tornin
henkipaton varmasti päässeen niin pitkälle, etteivät kuninkaan
miehet häntä saavuttaisi, ja niinpä tyttö virkkoi:

»Täällä kävi vähäistä ennen teidän tuloanne eräs soturi, joka ei


kuitenkaan nimittänyt itseään Norman of Torniksi, ja ehkä etsitte
juuri häntä.»

»Mitä tietä hän poistui?» huudahti upseeri.

»Suoraan länteen vievää keskimäistä tietä», valehteli Joan de


Tany. Ja kun upseeri kiiruhti linnasta ja lähti miestensä etunenässä
vimmatusti ratsastamaan länttä kohti, vaipui tyttö penkille ja painoi
pienet kätensä jyskyttäville ohimoilleen.

Sitten hän avasi Norman of Tornin antaman käärön. Sen sisällä oli
kaksi muuta. Toisessa niistä oli kaunis, jalokivillä koristettu
muistokotelo, jonka ulkopinnassa oli kirjaimet J.T. ja sisäpinnassa
kirjaimet N.T; toisessa oli kallisarvoinen, jalokiviupotuksilla
somistettu hiuskoru, jonka ympärille oli kierretty kihara hänen omia
silkinhienoja hiuksiaan.

Hän katseli kauan pieniä helyjä, painoi ne sitten huulilleen ja


heittäytyi kasvoilleen tammiselle penkille nyyhkytyksien puistattaessa
hänen joustavaa, nuorekasta vartaloaan.

Hän oli kun olikin vain pieni tyttö, joka oli järkkymättömillä siteillä
kahlittu säätynsä ennakkoluuloihin. Syntyperä ja yhteiskunnallinen
asema merkitsivät hänestä samaa kuin kunnia, ja kunnia oli
englantilaisen ylimyksen tyttärestä vieläkin valtavampi voima kuin
rakkaus.
Sen, että Norman of Torn oli henkipatto, hän olisi saattanut antaa
anteeksi, mutta se, että Norman kuulopuheiden mukaan oli
halpasyntyinen mies, jonka sukuperä oli tuntematon, nosti
ylipääsemättömän muurin heidän välilleen.

Tuntikausia tyttö virui nyyhkyttäen penkillä, samalla kun hänen


sisällään riehui valtava, sydämen ja pään välinen taistelu.

Sieltä hänen äitinsä löysi hänet, polvistui hänen viereensä, kiersi


kätensä hänen kaulaansa ja koetti tyynnyttää häntä, tiedustellen
hänen surunsa syytä. Vihdoin se tuli julki, tulvahtaen murheellisesta
sydämestä sellaisena toivottoman surkeuden hyökynä, jota ei edes
äidinrakkaus jaksanut hillitä.

»Joan, rakas tyttäreni», säälitteli lady de Tany, »suren kanssasi


sitä, että rakkautesi on ajautunut niin nurjalle ja mahdottomalle
rannalle. Mutta parempi on, että olet saanut tietää totuuden,
ennenkuin olisi liian myöhäistä, sillä usko minua, Joan, se katkera
nöyryytys, joka sellaisesta liitosta olisi välttämättä koitunut sinulle ja
isäsi suvulle, olisi pian jäähdyttänyt rakkautesi; eikä hänenkään
tunteensa olisi kestänyt sitä pilkkaa ja niitä herjauksia, joita hän olisi
saanut osakseen palkollistenkin taholta.»

»Voi, äiti, mutta minä rakastan häntä niin», valitti tyttö. »En
tiennyt, kuinka paljon häntä rakastin, ennenkuin hän oli poissa ja
kuninkaan upseeri saapui häntä etsimään, mutta silloin se ajatus,
että kokonaisen valtakunnan mahtavan valtaistuimen ja suurimpien
sukujen koko voima oli kiukkuisesti tähdätty häntä vastaan, tulistutti
vereni raivoiseksi ja tieto rakkaudestani valtasi koko olemukseni. Äiti,
sinä et voi tietää, kuinka kunniantuntoinen, uljas ja ritarillinen se
mies on, niinkuin minä tiedän. Sen jälkeen, kun silurien Arthur-
kuningas istui pyöreän pöytänsä ääressä, ei Englannin maaperällä
ole ratsastanut toista niin nuhteetonta ritaria kuin Norman of Torn
on.

»Jos vain olisit nähnyt, miten hän taisteli ja kuinka kunnioittavasti


hän kohteli tytärtäsi, ja kuullut, kuinka arvokkaan kunnioittavasti hän
puhui naisista, olisit sinäkin rakastanut häntä ja tuntenut, että vaikka
hän onkin henkipatto, hänessä sittenkin on enemmän kunnianmiestä
ja herrasmiestä kuin yhdeksässä kymmenesosassa Englannin
ylimyksiä.»

»Mutta hänen syntyperänsä, tyttäreni?» huomautti lady de Tany.


»Jotkut väittävät sellaistakin, että pronssisen orjanrenkaan hiertämät
jäljet vielä näkyvät hänen kaulassaan, ja toiset, ettei hän itsekään
tiedä isänsä nimeä ja ettei hänellä ole ollut äitiä.»

Niin, sepä tehokas perustelu! Tyttö ei osannut virkkaa mitään


puolustaakseen niin kamalaa rikosta kuin alhaista syntyperää. Kaikki
se, mitä mies teki, voitiin niinä julmina aikoina unohtaa ja antaa
anteeksi, mutta sitä hänen äitinsä tai iso-isänsä syntiä, etteivät he
kuuluneet aateliseen sukuun, vaikkapa kuinka pahamaineeseen, hän
ei ikinä voinut kiertää eikä elämällään sovittaa.

Ristiriitaisten tunteiden raatelemana tyttö laahusti omaan


huoneeseen ja paneutui levottomaan, unettomaan vuoteeseensa ja
hurjien, mahdottomien toiveiden ja turhien, rääkkäävien
pahoittelujen kalvamana kävi siellä taistelua koko pitkän, katkeran
yön, kunnes hän aamupuolella ratkaisi surkeutensa pulman sillä
ainoalla tavalla, joka hänen väsyneestä, vertavuotavasta, pienestä
sydän-parastaan tuntui mahdolliselta. Kun nouseva aurinko pilkisti
sisälle kapeasta ikkunasta, näki se Joan de Tanyn ja koko hänen
ympäristönsä rauhallisena; hänen vyössään riippuneen lelun
kaiverruksin koristettu, kultainen kahva pisti esiin hänen rinnastaan,
ja ohut, veripunainen juova ulottui lumivalkean ihon ylitse hänen
allansa olevalle raidille kertyneeseen pieneen lammikkoon.

Ja niin oli hirvittävän koston julma koura ojentunut ja rusentanut


vielä yhden viattoman uhrin.
VIIDESTOISTA LUKU

Kun sanoma Joan de Tanyn kuolemasta saapui Torniin, ei kukaan


olisi Tornin isännän ulkonäöstä aavistanut, kuinka syvää kärsimystä
tämä tieto hänelle tuotti.

Hänen seuralaisensa tiesivät vain sen, että annettiin eräitä


tavattomia määräyksiä ja että samana iltana kaikki kymmenen
komppaniaa ratsastivat etelään Essexiä kohti pysähtymättä matkalla
muutoin kuin ihmisten ja eläinten välttämättömiä ravinnon- ja
vedentarpeita tyydyttämään.

Kun Joan de Tanyn ruumista saatettiin hänen isänsä linnasta


Colchesterin kirkkoon ja sieltä takaisin lopulliseen leposijaansa linnan
hautakammioon, ratsasti tuhat outoa ja äänetöntä, mustiin verhottua
soturia mustatamineisilla hevosilla hitaasti saattueen jäljessä.

Äänettömästi he olivat tulleet hautajaisten edellisenä yönä, ja yhtä


hiljaa he katosivat pohjoista kohti seuraavan illan pidentyviin
varjoihin.

Linnan asukkaiden ja suurella joukolla saapuneiden surupukuisten


soturien kesken ei ollut lausuttu sanaakaan, mutta kaikki
linnassaolijat tiesivät mahtavan Tornin henkipaton tulleen
osoittamaan kunnioitustaan de Tanyn tyttären muistolle, ja kaikkia
muita paitsi murehtivaa äitiä ihmetytti tämä kummallinen teko.

Tornin sotalauman lähestyessä Derbyn linnoitusta luovutti nuori


johtaja päällikkyyden Punapää-Shandylle ja laskeutui ratsailta isä
Clauden asunnon ovella.

»Olen väsynyt, isä», valitti henkipatto heittäytyessään tavalliselle


istuimelleen, »Vain suru ja kuolema kulkevat jäljessäni. Minä ja
kaikki tekoni ovat kirottuja, ja kirous kohtaa niitä, joita rakastan.»

»Muuta elintapasi, poikani; noudata neuvoani, ennenkuin se on


liian myöhäistä! Etsi uutta ja parempaa elämää jossakin toisessa
maassa ja muovaa tulevaisuutesi kunniakkaaksi ja kunnioitetuksi!»

»Kunpa sen voisin tehdä, ystäväni!» vastasi Norman of Torn.


»Mutta oletko ajatellut, mitä varmasti olisi seurauksena, jos siten
riistäisi sekä sydämen että pään omalta luomaltani?

»Miten arvelisit käyvän, jos Norman of Torn päästäisi suuren


hirtehislaumansa johtajatta Englannin kimppuun? Oletko sitä
ajatellut vai etkö, isä?

»Hengittäisitkö hetkistäkään turvallisesti, jos tietäisit Orja-Edwildin


hillittömänä harhailevan Derbyssä? Edwildin, jonka isältä jäsen
toisensa jälkeen revittiin irti kidutustelineillä, koska hän ei
tunnustanut tappaneensa uudessa metsässä kaurista, joka oli
kaatunut toisen miehen nuolesta; Edwildin, jonka äidin pyhä kirkko
poltti noitana?

»Entä Tanskalais-Horsan? Kuinka turvallisia luulisit sekä rikkaiden


että köyhien olevan maanteillä, jos päästäisin Tanskalais-Horsanin
valloilleen heitä ahdistamaan?

»Entä espanjalainen don Pensilo? Etevä päällikkö, mutta tyyten


säälimätön mies. Kun hän liittyi meihin ja näki merkkimme
kaatuneiden vastustajaimme otsassa, halusi hän olla Herodestakin
herodesmaisempi ja merkitsi käsiinsä joutuneet elävät ihmiset,
polttaen tulikuumalla raudalla ison P:n heidän kumpaankin
poskeensa ja kärventäen oikean silmän täydelleen pois. Olisiko
sinusta, isä, mieluista tietää, että don Piedro Castro y Pensilo
samoilisi valtoimenaan Englannin metsissä ja kunnailla?

»Entä Punapää-Shandy, Flory-veljekset, Erakko-Peter, Silmäpuoli-


Kanty, Gropello, Campanie, Cobarth, Mandecote ja tuhat muuta,
joilla kullakin on jotakin erikoista kaunaa jotakin luokkaa tai yksilöä
vastaan ja joita kaikkia kannustaa veren-, ryöstön- ja saaliinhimo?

»Ei, isä, en saa vielä lähteä, sillä Englantia, jota minut on opetettu
vihaamaan, olen oppinut rakastamaan eikä sydämeni salli minun
päästää sen kaunista rintaa raastamaan hornamaisia petoja, jotka
eivät tunne muita lakeja, järjestystä ja säädyllisyyttä kuin ne, jotka
minä pidän voimassa.»

Norman of Tornin lakattua puhumasta istui pappi vaiti useita


minuutteja.

»Sinulla on tosiaankin suuri vastuunalaisuus, poikani», virkkoi hän


vihdoin. »Sinun ei hevin sovi lähteä, jollet vie muassasi laumaasi pois
Englannista, mutta sekin saattaa olla mahdollista; kukapa muu kuin
Jumala tietää?»

»Minä puolestani», tokaisi henkipatto nauraen, »olen valmis


luovuttamaan kaikki Hänen käsiinsä, kuten kristittyjen tapa näyttää

You might also like