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

Java EE 7 Recipes A Problem Solution Approach 1st Edition Juneau Josh pdf download

The document is about 'Java EE 7 Recipes: A Problem-Solution Approach' by Josh Juneau, providing practical solutions for Java EE development. It includes various chapters covering topics such as Servlets, JavaServer Pages, JavaServer Faces, and more, with a focus on problem-solving techniques. The book is intended for Java developers looking to enhance their skills and create sophisticated applications.

Uploaded by

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

Java EE 7 Recipes A Problem Solution Approach 1st Edition Juneau Josh pdf download

The document is about 'Java EE 7 Recipes: A Problem-Solution Approach' by Josh Juneau, providing practical solutions for Java EE development. It includes various chapters covering topics such as Servlets, JavaServer Pages, JavaServer Faces, and more, with a focus on problem-solving techniques. The book is intended for Java developers looking to enhance their skills and create sophisticated applications.

Uploaded by

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

Java EE 7 Recipes A Problem Solution Approach

1st Edition Juneau Josh download

https://textbookfull.com/product/java-ee-7-recipes-a-problem-
solution-approach-1st-edition-juneau-josh/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Java 9 Recipes: A Problem-Solution Approach 3rd Edition


Josh Juneau

https://textbookfull.com/product/java-9-recipes-a-problem-
solution-approach-3rd-edition-josh-juneau/

Java 7 Recipes A Problem Solution Approach Juneau Josh


Beaty Mark Dea Carl Guime Freddy Oconner John

https://textbookfull.com/product/java-7-recipes-a-problem-
solution-approach-juneau-josh-beaty-mark-dea-carl-guime-freddy-
oconner-john/

Introducing Java EE 7 A Look at What s New Juneau Josh

https://textbookfull.com/product/introducing-java-ee-7-a-look-at-
what-s-new-juneau-josh/

Java 8 Recipes 2nd Edition Josh Juneau

https://textbookfull.com/product/java-8-recipes-2nd-edition-josh-
juneau/
Android Recipes A Problem-Solution Approach Dave Smith

https://textbookfull.com/product/android-recipes-a-problem-
solution-approach-dave-smith/

Raku Recipes: A Problem-Solution Approach J.J. Merelo

https://textbookfull.com/product/raku-recipes-a-problem-solution-
approach-j-j-merelo/

C Recipes - A Problem-Solution Approach 1st Edition


Shirish Chavan

https://textbookfull.com/product/c-recipes-a-problem-solution-
approach-1st-edition-shirish-chavan/

JavaScript Recipes: A Problem-Solution Approach 1st


Edition Russ Ferguson

https://textbookfull.com/product/javascript-recipes-a-problem-
solution-approach-1st-edition-russ-ferguson/

wxPython Recipes: A Problem - Solution Approach 1st


Edition Mike Driscoll

https://textbookfull.com/product/wxpython-recipes-a-problem-
solution-approach-1st-edition-mike-driscoll/
Java EE 7 Recipes
A Problem-Solution Approach

Josh Juneau

Apress
Java EE 7 Recipes: A Problem-Solution Approach
Copyright © 2013 by Josh Juneau
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material
is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting,
reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material
supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the
purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the
Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from
Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are
liable to prosecution under the respective Copyright Law.
ISBN 978-1-4302-4425-7
ISBN 978-1-4302-4426-4 (eBook)
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion
and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified
as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither
the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may
be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
President and Publisher: Paul Manning
Lead Editor: Jonathan Gennick
Technical Reviewers: David Coffin and Mark Beaty
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Louise Corrigan, Morgan Ertel,
Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham,
Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft,
Gwenan Spearing, Matt Wade, Tom Welsh
Coordinating Editor: Kevin Shea
Copy Editors: Kim Wimpsett and Kimberly Burton
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing
web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text is available to readers at
www.apress.com. For detailed information about how to locate your book’s source code, go to
www.apress.com/source-code.
This book is dedicated to my wife, Angela, and my four children—Kaitlyn, Jacob, Matthew, and Zachary.
You are my joy and inspiration. This book is also dedicated to the many Java developers worldwide.
I hope that these recipes can lead you to developing the sophisticated solutions of tomorrow.
— Josh Juneau
Contents at a Glance

About the Author .......................................................................................................... xxxvii


About the Technical Reviewers ..................................................................................... xxxix
Acknowledgments ..............................................................................................................xli
Introduction ......................................................................................................................xliii

N Chapter 1: Introduction to Servlets ...................................................................................1


N Chapter 2: JavaServer Pages ..........................................................................................53
N Chapter 3: The Basics of JavaServer Faces ....................................................................97
N Chapter 4: Facelets ........................................................................................................159
N Chapter 5: JavaServer Faces Standard Components ....................................................199
N Chapter 6: Advanced JavaServer Faces and Ajax .........................................................255
N Chapter 7: JDBC.............................................................................................................317
N Chapter 8: Object-Relational Mapping...........................................................................369
N Chapter 9: Enterprise JavaBeans ..................................................................................409
N Chapter 10: The Query API and JPQL.............................................................................447
N Chapter 11: Oracle’s GlassFish ......................................................................................471
N Chapter 12: Contexts and Dependency Injection ...........................................................497
N Chapter 13: Java Message Service ...............................................................................517
N Chapter 14: Authentication and Security ......................................................................537
N Chapter 15: Java Web Services .....................................................................................563
N Chapter 16: Enterprise Solutions Using Alternative Programming Languages...............597

v
N CONTENTS AT A GLANCE

N Chapter 17: WebSockets and JSON-P............................................................................605


N Chapter 18: JavaFX in the Enterprise ............................................................................615
N Chapter 19: Concurrency and Batch Applications .........................................................647
N Appendix A: Java EE Development with NetBeans IDE ..................................................671

Index .................................................................................................................................683

vi
Contents

About the Author .......................................................................................................... xxxvii


About the Technical Reviewers ..................................................................................... xxxix
Acknowledgments ..............................................................................................................xli
Introduction ...................................................................................................................... xliii

N Chapter 1: Introduction to Servlets ...................................................................................1


1-1. Setting Up a Java Enterprise Environment ............................................................................2
Problem ................................................................................................................................................................. 2
Solution.................................................................................................................................................................. 2
How It Works.......................................................................................................................................................... 2

1-2. Developing a Servlet ..............................................................................................................3


Problem ................................................................................................................................................................. 3
Solution.................................................................................................................................................................. 3
How It Works.......................................................................................................................................................... 5

1-3. Packaging, Compiling, and Deploying a Servlet .....................................................................7


Problem ................................................................................................................................................................. 7
Solution.................................................................................................................................................................. 7
How It Works.......................................................................................................................................................... 8

1-4. Registering Servlets Without WEB-XML .................................................................................9


Problem ................................................................................................................................................................. 9
Solution.................................................................................................................................................................. 9
How It Works........................................................................................................................................................ 11

vii
N CONTENTS

1-5. Displaying Dynamic Content with a Servlet .........................................................................12


Problem ............................................................................................................................................................... 12
Solution................................................................................................................................................................ 12
How It Works........................................................................................................................................................ 14

1-6. Handling Requests and Responses......................................................................................15


Problem ............................................................................................................................................................... 15
Solution................................................................................................................................................................ 15
How It Works........................................................................................................................................................ 17

1-7. Listening for Servlet Container Events.................................................................................18


Problem ............................................................................................................................................................... 18
Solution................................................................................................................................................................ 18
How It Works........................................................................................................................................................ 20

1-8. Setting Initialization Parameters..........................................................................................21


Problem ............................................................................................................................................................... 21
Solution #1........................................................................................................................................................... 21
Solution #2........................................................................................................................................................... 22
How It Works........................................................................................................................................................ 22

1-9. Filtering Web Requests ........................................................................................................23


Problem ............................................................................................................................................................... 23
Solution................................................................................................................................................................ 23
How It Works........................................................................................................................................................ 24

1-10. Listening for Attribute Changes .........................................................................................25


Problem ............................................................................................................................................................... 25
Solution................................................................................................................................................................ 25
How It Works........................................................................................................................................................ 26

1-11. Applying a Listener to a Session ........................................................................................27


Problem ............................................................................................................................................................... 27
Solution................................................................................................................................................................ 27
How It Works........................................................................................................................................................ 28

viii
N CONTENTS

1-12. Managing Session Attributes .............................................................................................29


Problem ............................................................................................................................................................... 29
Solution................................................................................................................................................................ 29
How It Works........................................................................................................................................................ 31

1-13. Downloading a File ............................................................................................................31


Problem ............................................................................................................................................................... 31
Solution................................................................................................................................................................ 31
How It Works........................................................................................................................................................ 34

1-14. Dispatching Requests ........................................................................................................35


Problem ............................................................................................................................................................... 35
Solution................................................................................................................................................................ 35
How It Works........................................................................................................................................................ 39

1-15. Redirecting to a Different Site ...........................................................................................40


Problem ............................................................................................................................................................... 40
Solution................................................................................................................................................................ 40
How It Works........................................................................................................................................................ 40

1-16. Securely Maintaining State Within the Browser ................................................................41


Problem ............................................................................................................................................................... 41
Solution................................................................................................................................................................ 41
How It Works........................................................................................................................................................ 43

1-17. Finalizing Servlet Tasks .....................................................................................................45


Problem ............................................................................................................................................................... 45
Solution................................................................................................................................................................ 45
How It Works........................................................................................................................................................ 45

1-18. Reading and Writing with Nonblocking I/O ........................................................................46


Problem ............................................................................................................................................................... 46
Solution................................................................................................................................................................ 46
How It Works........................................................................................................................................................ 50

ix
N CONTENTS

N Chapter 2: JavaServer Pages ..........................................................................................53


2-1. Creating a Simple JSP Page ................................................................................................53
Problem ............................................................................................................................................................... 53
Solution................................................................................................................................................................ 54
How It Works........................................................................................................................................................ 55

2-2. Embedding Java into a JSP Page ........................................................................................56


Problem ............................................................................................................................................................... 56
Solution................................................................................................................................................................ 56
How It Works........................................................................................................................................................ 57

2-3. Separating Business Logic from View Code ........................................................................58


Problem ............................................................................................................................................................... 58
Solution................................................................................................................................................................ 58
How It Works........................................................................................................................................................ 59

2-4. Yielding or Setting Values ....................................................................................................60


Problem ............................................................................................................................................................... 60
Solution................................................................................................................................................................ 60
How It Works........................................................................................................................................................ 62

2-5. Invoking a Function in a Conditional Expression .................................................................63


Problem ............................................................................................................................................................... 63
Solution................................................................................................................................................................ 63
How It Works........................................................................................................................................................ 66

2-6. Creating a JSP Document ....................................................................................................67


Problem ............................................................................................................................................................... 67
Solution................................................................................................................................................................ 67
How It Works........................................................................................................................................................ 68

2-7. Embedding Expressions in EL ..............................................................................................69


Problem ............................................................................................................................................................... 69
Solution................................................................................................................................................................ 69
How It Works........................................................................................................................................................ 71

x
N CONTENTS

2-8. Accessing Parameters in Multiple Pages .............................................................................74


Problem ............................................................................................................................................................... 74
Solution................................................................................................................................................................ 75
How It Works........................................................................................................................................................ 76

2-9. Creating a Custom JSP Tag ..................................................................................................77


Problem ............................................................................................................................................................... 77
Solution................................................................................................................................................................ 77
How It Works........................................................................................................................................................ 79

2-10. Including Other JSPs into a Page.......................................................................................81


Problem ............................................................................................................................................................... 81
Solution................................................................................................................................................................ 81
How It Works........................................................................................................................................................ 82

2-11. Creating an Input Form for a Database Record..................................................................83


Problem ............................................................................................................................................................... 83
Solution................................................................................................................................................................ 83
How It Works........................................................................................................................................................ 86

2-12. Looping Through Database Records Within a Page ...........................................................87


Problem ............................................................................................................................................................... 87
Solution................................................................................................................................................................ 87
How It Works........................................................................................................................................................ 91

2-13. Handling JSP Errors ...........................................................................................................91


Problem ............................................................................................................................................................... 91
Solution................................................................................................................................................................ 91
How It Works........................................................................................................................................................ 93

2-14. Disabling Scriptlets in Pages .............................................................................................94


Problem ............................................................................................................................................................... 94
Solution................................................................................................................................................................ 94
How It Works........................................................................................................................................................ 94

xi
N CONTENTS

2-15. Ignoring EL in Pages ..........................................................................................................95


Problem ............................................................................................................................................................... 95
Solution #1........................................................................................................................................................... 95
Solution #2........................................................................................................................................................... 95
Solution #3........................................................................................................................................................... 95
How It Works........................................................................................................................................................ 96

N Chapter 3: The Basics of JavaServer Faces ....................................................................97


3-1. Writing a Simple JSF Application .........................................................................................97
Problem ............................................................................................................................................................... 97
Solution #1........................................................................................................................................................... 98
Solution #2......................................................................................................................................................... 100
How It Works...................................................................................................................................................... 102
3-2. Writing a Managed Bean ....................................................................................................103
Problem ............................................................................................................................................................. 103
Solution.............................................................................................................................................................. 104
How It Works...................................................................................................................................................... 108

3-3. Building Sophisticated JSF Views with Components .........................................................110


Problem ............................................................................................................................................................. 110
Solution.............................................................................................................................................................. 110
How It Works...................................................................................................................................................... 116

3-4. Displaying Messages in JSF Pages ...................................................................................118


Problem ............................................................................................................................................................. 118
Solution.............................................................................................................................................................. 118
How It Works...................................................................................................................................................... 121

3-5. Navigation Based Upon Conditions ....................................................................................122


Problem ............................................................................................................................................................. 122
Solution.............................................................................................................................................................. 123
How It Works...................................................................................................................................................... 128

xii
N CONTENTS

3-6. Updating Messages Without Recompiling .........................................................................129


Problem ............................................................................................................................................................. 129
Solution ............................................................................................................................................................. 129
How It Works...................................................................................................................................................... 131

3-7. Validating User Input ..........................................................................................................132


Problem ............................................................................................................................................................. 132
Solution.............................................................................................................................................................. 132
How It Works...................................................................................................................................................... 138

3-8. Evaluation of Page Expressions Immediately ....................................................................139


Problem ............................................................................................................................................................. 139
Solution.............................................................................................................................................................. 139
How It Works...................................................................................................................................................... 141

3-9. Passing Page Parameters to Methods ...............................................................................141


Problem ............................................................................................................................................................. 141
Solution.............................................................................................................................................................. 141
How It Works...................................................................................................................................................... 145

3-10. Arithmetic and Reserved Words in Expressions...............................................................146


Problem ............................................................................................................................................................. 146
Solution ............................................................................................................................................................. 146
How It Works...................................................................................................................................................... 148

3-11. Creating Bookmarkable URLs ..........................................................................................150


Problem ............................................................................................................................................................. 150
Solution.............................................................................................................................................................. 150
How It Works...................................................................................................................................................... 152

3-12. Displaying Lists of Objects...............................................................................................153


Problem ............................................................................................................................................................. 153
Solution ............................................................................................................................................................. 153
How It Works...................................................................................................................................................... 155

xiii
N CONTENTS

3-13. Invoking Managed Bean Actions on Life-Cycle Phase Events .........................................157


Problem ............................................................................................................................................................. 157
Solution.............................................................................................................................................................. 157
How It Works...................................................................................................................................................... 157

N Chapter 4: Facelets ........................................................................................................159


4-1. Creating a Page Template ..................................................................................................159
Problem ............................................................................................................................................................. 159
Solution.............................................................................................................................................................. 159
How It Works...................................................................................................................................................... 161

4-2. Applying a Template to Your Views ....................................................................................164


Problem ............................................................................................................................................................. 164
Solution.............................................................................................................................................................. 164
How It Works...................................................................................................................................................... 171

4-3. Ensuring Resource Availability from All Views ...................................................................174


Problem ............................................................................................................................................................. 174
Solution.............................................................................................................................................................. 174
How It Works...................................................................................................................................................... 177

4-4. Creating Reusable Templates That Act As Components .....................................................177


Problem ............................................................................................................................................................. 177
Solution.............................................................................................................................................................. 177
How It Works...................................................................................................................................................... 185

4-5. Handling Variable-Length Data on a Page .........................................................................187


Problem ............................................................................................................................................................. 187
Solution.............................................................................................................................................................. 188
How It Works...................................................................................................................................................... 190
4-6. Debugging View Content ....................................................................................................195
Problem ............................................................................................................................................................. 195
Solution.............................................................................................................................................................. 195
How It Works...................................................................................................................................................... 197

xiv
N CONTENTS

4-7. Writing a Custom Resolver for Locating Facelets Templates and Resources ....................197
Problem ............................................................................................................................................................. 197
Solution.............................................................................................................................................................. 197
How It Works...................................................................................................................................................... 198

N Chapter 5: JavaServer Faces Standard Components ....................................................199


Component and Tag Primer .......................................................................................................199
Common Component Tag Attributes .................................................................................................................. 201
Common JavaScript Component Tags ............................................................................................................... 202
Binding Components to Properties .................................................................................................................... 203

5-1. Creating an Input Form ......................................................................................................203


Problem ............................................................................................................................................................. 203
Solution.............................................................................................................................................................. 203
How It Works...................................................................................................................................................... 207

5-2. Invoking Actions from Within a Page .................................................................................209


Problem ............................................................................................................................................................. 209
Solution.............................................................................................................................................................. 209
How It Works...................................................................................................................................................... 212

5-3. Displaying Output...............................................................................................................214


Problem ............................................................................................................................................................. 214
Solution.............................................................................................................................................................. 214
How It Works...................................................................................................................................................... 217

5-4. Adding Form Validation ......................................................................................................220


Problem ............................................................................................................................................................. 220
Solution #1......................................................................................................................................................... 220
Solution #2......................................................................................................................................................... 221
Solution #3......................................................................................................................................................... 222
How It Works...................................................................................................................................................... 224
5-5. Adding Select Lists to Pages..............................................................................................226
Problem ............................................................................................................................................................. 226
Solution.............................................................................................................................................................. 226
How It Works...................................................................................................................................................... 229

xv
N CONTENTS

5-6. Adding Graphics to Your Pages ..........................................................................................230


Problem ............................................................................................................................................................. 230
Solution.............................................................................................................................................................. 230
How It Works...................................................................................................................................................... 231

5-7. Adding Check Boxes to a View ...........................................................................................231


Problem ............................................................................................................................................................. 231
Solution.............................................................................................................................................................. 231
How It Works...................................................................................................................................................... 234

5-8. Adding Radio Buttons to a View .........................................................................................236


Problem ............................................................................................................................................................. 236
Solution.............................................................................................................................................................. 236
How It Works...................................................................................................................................................... 237

5-9. Structuring View Layout .....................................................................................................238


Problem ............................................................................................................................................................. 238
Solution.............................................................................................................................................................. 238
How It Works...................................................................................................................................................... 242

5-10. Displaying a Collection of Data ........................................................................................245


Problem ............................................................................................................................................................. 245
Solution.............................................................................................................................................................. 245
How It Works...................................................................................................................................................... 249

5-11. Utilizing Custom JSF Component Libraries ......................................................................252


Problem ............................................................................................................................................................. 252
Solution.............................................................................................................................................................. 252
How It Works...................................................................................................................................................... 252

5-12. Implementing File Uploading ...........................................................................................253


Problem ............................................................................................................................................................. 253
Solution.............................................................................................................................................................. 253
How It Works...................................................................................................................................................... 253

xvi
N CONTENTS

N Chapter 6: Advanced JavaServer Faces and Ajax ................................................... 255


6-1. Validating Input with Ajax.............................................................................................255
Problem ......................................................................................................................................................255
Solution.......................................................................................................................................................256
How It Works...............................................................................................................................................260
6-2. Submitting Pages Without Page Reloads .....................................................................262
Problem ......................................................................................................................................................262
Solution.......................................................................................................................................................262
How It Works...............................................................................................................................................263

6-3. Making Partial-Page Updates ......................................................................................263


Problem ......................................................................................................................................................263
Solution.......................................................................................................................................................264
How It Works...............................................................................................................................................264

6-4. Applying Ajax Functionality to a Group of Components ...............................................265


Problem ......................................................................................................................................................265
Solution.......................................................................................................................................................265
How It Works...............................................................................................................................................269

6-5. Custom Processing of Ajax Functionality .....................................................................269


Problem ......................................................................................................................................................269
Solution.......................................................................................................................................................269
How It Works...............................................................................................................................................271

6-6. Custom Conversion of Input Values .............................................................................271


Problem ......................................................................................................................................................271
Solution.......................................................................................................................................................272
How It Works...............................................................................................................................................273
6-7. Maintaining Managed Bean Scopes for a Session.......................................................274
Problem ......................................................................................................................................................274
Solution.......................................................................................................................................................274
How It Works...............................................................................................................................................282

xvii
N CONTENTS

6-8. Listening for System-Level Events ....................................................................................283


Problem ............................................................................................................................................................. 283
Solution.............................................................................................................................................................. 283
How It Works...................................................................................................................................................... 284

6-9. Listening for Component Events ........................................................................................285


Problem ............................................................................................................................................................. 285
Solution.............................................................................................................................................................. 285
How It Works...................................................................................................................................................... 286

6-10. Invoking a Managed Bean Action on Render ...................................................................286


Problem ............................................................................................................................................................. 286
Solution.............................................................................................................................................................. 286
How It Works...................................................................................................................................................... 288

6-11. Asynchronously Updating Components ...........................................................................289


Problem ............................................................................................................................................................. 289
Solution.............................................................................................................................................................. 289
How It Works...................................................................................................................................................... 291

6-12. Developing JSF Components Containing HTML5 .............................................................292


Problem ............................................................................................................................................................. 292
Solution.............................................................................................................................................................. 292
How It Works...................................................................................................................................................... 294

6-13. Listening to JSF Phases ...................................................................................................295


Problem ............................................................................................................................................................. 295
Solution.............................................................................................................................................................. 295
How It Works...................................................................................................................................................... 296

6-14. Adding Autocompletion to Text Fields ..............................................................................297


Problem ............................................................................................................................................................. 297
Solution.............................................................................................................................................................. 297
How It Works...................................................................................................................................................... 299

xviii
N CONTENTS

6-15. Developing Custom Constraint Annotations .....................................................................300


Problem ............................................................................................................................................................. 300
Solution.............................................................................................................................................................. 300
How It Works...................................................................................................................................................... 302

6-16. Customizing Data Tables ..................................................................................................304


Problem ............................................................................................................................................................. 304
Solution.............................................................................................................................................................. 304
How It Works...................................................................................................................................................... 306

6-17. Developing a Page Flow...................................................................................................308


Problem ............................................................................................................................................................. 308
Solution.............................................................................................................................................................. 308
How It Works...................................................................................................................................................... 311

6-18. Constructing a JSF View in Pure HTML5 ..........................................................................314


Problem ............................................................................................................................................................. 314
Solution.............................................................................................................................................................. 314
How It Works...................................................................................................................................................... 315

N Chapter 7: JDBC.............................................................................................................317
7-1. Obtaining Database Drivers and Adding Them to the CLASSPATH .....................................317
Problem ............................................................................................................................................................. 317
Solution.............................................................................................................................................................. 318
How It Works...................................................................................................................................................... 318

7-2. Connecting to a Database ..................................................................................................319


Problem ............................................................................................................................................................. 319
Solution #1......................................................................................................................................................... 319
Solution #2......................................................................................................................................................... 319
How It Works...................................................................................................................................................... 322
7-3. Handling Database Connection Exceptions .......................................................................324
Problem ............................................................................................................................................................. 324
Solution.............................................................................................................................................................. 324
How It Works...................................................................................................................................................... 325

xix
N CONTENTS

7-4. Simplifying Connection Management ................................................................................325


Problem ............................................................................................................................................................. 325
Solution.............................................................................................................................................................. 325
How It Works...................................................................................................................................................... 329

7-5. Querying a Database..........................................................................................................329


Problem ............................................................................................................................................................. 329
Solution.............................................................................................................................................................. 330
How It Works...................................................................................................................................................... 330

7-6. Performing CRUD Operations .............................................................................................332


Problem ............................................................................................................................................................. 332
Solution.............................................................................................................................................................. 332
How It Works...................................................................................................................................................... 334

7-7. Preventing SQL Injection ....................................................................................................335


Problem ............................................................................................................................................................. 335
Solution.............................................................................................................................................................. 335
How It Works...................................................................................................................................................... 339

7-8. Utilizing Java Objects for Database Access .......................................................................341


Problem ............................................................................................................................................................. 341
Solution.............................................................................................................................................................. 341
How It Works...................................................................................................................................................... 347

7-9. Displaying Database Results in JSF Views ........................................................................348


Problem ............................................................................................................................................................. 348
Solution.............................................................................................................................................................. 348
How It Works...................................................................................................................................................... 351

7-10. Navigating Data with Scrollable ResultSets ....................................................................351


Problem ............................................................................................................................................................. 351
Solution.............................................................................................................................................................. 351
How It Works...................................................................................................................................................... 352

xx
N CONTENTS

7-11. Calling PL/SQL Stored Procedures ...................................................................................353


Problem ............................................................................................................................................................. 353
Solution.............................................................................................................................................................. 353
How It Works...................................................................................................................................................... 354

7-12. Querying and Storing Large Objects ................................................................................355


Problem ............................................................................................................................................................. 355
Solution.............................................................................................................................................................. 355
How It Works...................................................................................................................................................... 357

7-13. Caching Data for Use When Disconnected .......................................................................358


Problem ............................................................................................................................................................. 358
Solution.............................................................................................................................................................. 358
How It Works...................................................................................................................................................... 361

7-14. Joining RowSet Objects When Not Connected to the Data Source ..................................363
Problem ............................................................................................................................................................. 363
Solution.............................................................................................................................................................. 364
How It Works...................................................................................................................................................... 367

N Chapter 8: Object-Relational Mapping...........................................................................369


8-1. Creating an Entity ..............................................................................................................370
Problem ............................................................................................................................................................. 370
Solution.............................................................................................................................................................. 370
How It Works...................................................................................................................................................... 372

8-2. Mapping Data Types...........................................................................................................374


Problem ............................................................................................................................................................. 374
Solution.............................................................................................................................................................. 374
How It Works...................................................................................................................................................... 376
8-3. Creating a Persistence Unit ...............................................................................................377
Problem ............................................................................................................................................................. 377
Solution.............................................................................................................................................................. 377
How It Works...................................................................................................................................................... 378

xxi
N CONTENTS

8-4. Using Database Sequences to Create Primary Key Values ................................................380


Problem ............................................................................................................................................................. 380
Solution.............................................................................................................................................................. 380
How It Works...................................................................................................................................................... 382

8-5. Generating Primary Keys with More Than One Attribute....................................................383


Problem ............................................................................................................................................................. 383
Solution #1......................................................................................................................................................... 383
Solution #2......................................................................................................................................................... 386
How It Works...................................................................................................................................................... 389

8-6. Defining a One-to-One Relationship ..................................................................................391


Problem ............................................................................................................................................................. 391
Solution.............................................................................................................................................................. 391
How It Works...................................................................................................................................................... 393

8-7. Defining One-to-Many and Many-to-One Relationships ....................................................394


Problem ............................................................................................................................................................. 394
Solution.............................................................................................................................................................. 394
How It Works...................................................................................................................................................... 396

8-8. Defining a Many-to-Many Relationship .............................................................................397


Problem ............................................................................................................................................................. 397
Solution.............................................................................................................................................................. 398
How It Works...................................................................................................................................................... 399

8-9. Querying with Named Queries ...........................................................................................401


Problem ............................................................................................................................................................. 401
Solution.............................................................................................................................................................. 401
How It Works...................................................................................................................................................... 402
8-10. Performing Validation on Entity Fields .............................................................................402
Problem ............................................................................................................................................................. 402
Solution.............................................................................................................................................................. 403
How It Works...................................................................................................................................................... 404

xxii
N CONTENTS

8-11. Generating Database Schema Objects Automatically ......................................................404


Problem ............................................................................................................................................................. 404
Solution.............................................................................................................................................................. 405
How It Works...................................................................................................................................................... 405

N Chapter 9: Enterprise JavaBeans ..................................................................................409


9-1. Obtaining an Entity Manager .............................................................................................409
Problem ............................................................................................................................................................. 409
Solution #1......................................................................................................................................................... 410
Solution #2......................................................................................................................................................... 410
How It Works...................................................................................................................................................... 410

9-2. Developing a Stateless Session Bean ................................................................................411


Problem ............................................................................................................................................................. 411
Solution #1......................................................................................................................................................... 411
Solution #2......................................................................................................................................................... 412
How It Works...................................................................................................................................................... 415

9-3. Developing a Stateful Session Bean ..................................................................................417


Problem ............................................................................................................................................................. 417
Solution.............................................................................................................................................................. 417
How It Works...................................................................................................................................................... 421

9-4. Utilizing Session Beans with JSF .......................................................................................422


Problem ............................................................................................................................................................. 422
Solution #1......................................................................................................................................................... 422
Solution #2......................................................................................................................................................... 425
How It Works...................................................................................................................................................... 427

9-5. Persisting an Object ...........................................................................................................429


Problem ............................................................................................................................................................. 429
Solution.............................................................................................................................................................. 429
How It Works...................................................................................................................................................... 429

xxiii
N CONTENTS

9-6. Updating an Object ............................................................................................................429


Problem ............................................................................................................................................................. 429
Solution.............................................................................................................................................................. 429
How It Works...................................................................................................................................................... 430

9-7. Returning a Table Model ....................................................................................................430


Problem ............................................................................................................................................................. 430
Solution #1......................................................................................................................................................... 430
Solution #2......................................................................................................................................................... 432
How It Works...................................................................................................................................................... 433

9-8. Creating a Singleton Bean .................................................................................................434


Problem ............................................................................................................................................................. 434
Solution.............................................................................................................................................................. 434
How It Works...................................................................................................................................................... 436

9-9. Scheduling a Timer Service ...............................................................................................437


Problem ............................................................................................................................................................. 437
Solution #1......................................................................................................................................................... 437
Solution #2......................................................................................................................................................... 438
How It Works...................................................................................................................................................... 438

9-10. Performing Optional Transaction Life-Cycle Callbacks ....................................................441


Problem ............................................................................................................................................................. 441
Solution.............................................................................................................................................................. 441
How It Works...................................................................................................................................................... 442

9-11. Ensuring a Stateful Session Bean Is Not Passivated .......................................................442


Problem ............................................................................................................................................................. 442
Solution.............................................................................................................................................................. 442
How It Works...................................................................................................................................................... 443

9-12. Denoting Local and Remote Interfaces ............................................................................443


Problem ............................................................................................................................................................. 443
Solution.............................................................................................................................................................. 443
How It Works...................................................................................................................................................... 443

xxiv
N CONTENTS

9-13. Processing Messages Asynchronously from Enterprise Beans .......................................444


Problem ............................................................................................................................................................. 444
Solution.............................................................................................................................................................. 445
How It Works...................................................................................................................................................... 445

N Chapter 10: The Query API and JPQL.............................................................................447


10-1. Querying All Instances of an Entity ..................................................................................448
Problem ............................................................................................................................................................. 448
Solution #1......................................................................................................................................................... 448
Solution #2......................................................................................................................................................... 448
How It Works...................................................................................................................................................... 448

10-2. Setting Parameters to Filter Query Results......................................................................450


Problem ............................................................................................................................................................. 450
Solution.............................................................................................................................................................. 450
How It Works...................................................................................................................................................... 450

10-3. Returning a Single Object ................................................................................................451


Problem ............................................................................................................................................................. 451
Solution.............................................................................................................................................................. 451
How It Works...................................................................................................................................................... 452

10-4. Creating Native Queries ...................................................................................................452


Problem ............................................................................................................................................................. 452
Solution #1......................................................................................................................................................... 452
Solution #2......................................................................................................................................................... 452
How It Works...................................................................................................................................................... 453

10-5. Querying More Than One Entity .......................................................................................454


Problem ............................................................................................................................................................. 454
Solution #1......................................................................................................................................................... 454
Solution #2......................................................................................................................................................... 455
How It Works...................................................................................................................................................... 456

xxv
N CONTENTS

10-6. Calling JPQL Aggregate Functions ...................................................................................458


Problem ............................................................................................................................................................. 458
Solution.............................................................................................................................................................. 458
How It Works...................................................................................................................................................... 458

10-7. Invoking Database Stored Procedures Natively ...............................................................459


Problem ............................................................................................................................................................. 459
Solution.............................................................................................................................................................. 459
How It Works...................................................................................................................................................... 460

10-8. Joining to Retrieve Instances Matching All Cases ...........................................................460


Problem ............................................................................................................................................................. 460
Solution.............................................................................................................................................................. 460
How It Works...................................................................................................................................................... 461

10-9. Joining to Retrieve All Rows Regardless of Match ..........................................................461


Problem ............................................................................................................................................................. 461
Solution.............................................................................................................................................................. 461
How It Works...................................................................................................................................................... 462

10-10. Applying JPQL Functional Expressions ..........................................................................462


Problem ............................................................................................................................................................. 462
Solution.............................................................................................................................................................. 462
How It Works...................................................................................................................................................... 463

10-11. Forcing Query Execution Rather Than Cache Use ..........................................................464


Problem ............................................................................................................................................................. 464
Solution.............................................................................................................................................................. 464
How It Works...................................................................................................................................................... 465

10-12. Performing Bulk Updates and Deletes ...........................................................................465


Problem ............................................................................................................................................................. 465
Solution.............................................................................................................................................................. 465
How It Works...................................................................................................................................................... 466

xxvi
N CONTENTS

10-13. Retrieving Entity Subclasses .........................................................................................467


Problem ............................................................................................................................................................. 467
Solution.............................................................................................................................................................. 467
How It Works...................................................................................................................................................... 468

10-14. Joining with ON Conditions ............................................................................................468


Problem ............................................................................................................................................................. 468
Solution.............................................................................................................................................................. 468
How It Works...................................................................................................................................................... 469

N Chapter 11: Oracle’s GlassFish ......................................................................................471


11-1. Installing the GlassFish Application Server ......................................................................471
Problem ............................................................................................................................................................. 471
Solution #1......................................................................................................................................................... 471
Solution #2......................................................................................................................................................... 471
How It Works...................................................................................................................................................... 475

11-2. Logging into the Administrative Console .........................................................................476


Problem ............................................................................................................................................................. 476
Solution.............................................................................................................................................................. 476
How It Works...................................................................................................................................................... 478

11-3. Changing the Administrator User Password ....................................................................480


Problem ............................................................................................................................................................. 480
Solution #1......................................................................................................................................................... 481
Solution #2......................................................................................................................................................... 481
How It Works...................................................................................................................................................... 481

11-4. Deploying a WAR File .......................................................................................................482


Problem ............................................................................................................................................................. 482
Solution #1......................................................................................................................................................... 482
Solution #2......................................................................................................................................................... 483
How It Works...................................................................................................................................................... 483

xxvii
N CONTENTS

11-5. Adding a Database Resource ...........................................................................................484


Problem ............................................................................................................................................................. 484
Solution.............................................................................................................................................................. 484
How It Works...................................................................................................................................................... 487

11-6. Adding Forms-Based Authentication ...............................................................................488


Problem ............................................................................................................................................................. 488
Solution.............................................................................................................................................................. 488
How It Works...................................................................................................................................................... 493

11-7. Configuring and Using JavaMail ......................................................................................494


Problem ............................................................................................................................................................. 494
Solution.............................................................................................................................................................. 494
How It Works...................................................................................................................................................... 496

N Chapter 12: Contexts and Dependency Injection ...........................................................497


12-1. Injecting a Bean or Other Object ......................................................................................497
Problem ............................................................................................................................................................. 497
Solution.............................................................................................................................................................. 497
How It Works...................................................................................................................................................... 498

12-2. Binding a Bean to JSF Views ...........................................................................................499


Problem ............................................................................................................................................................. 499
Solution #1......................................................................................................................................................... 499
Solution #2......................................................................................................................................................... 501
How It Works...................................................................................................................................................... 502

12-3. Allocating a Specific Bean for Injection ...........................................................................503


Problem ............................................................................................................................................................. 503
Solution.............................................................................................................................................................. 503
How It Works...................................................................................................................................................... 505

12-4. Determining Scope of a Bean ..........................................................................................506


Problem ............................................................................................................................................................. 506
Solution.............................................................................................................................................................. 506
How It Works...................................................................................................................................................... 507

xxviii
N CONTENTS

12-5. Injecting Non-bean Objects .............................................................................................508


Problem ............................................................................................................................................................. 508
Solution #1......................................................................................................................................................... 508
How It Works...................................................................................................................................................... 511

12-6. Ignoring Classes ..............................................................................................................512


Problem ............................................................................................................................................................. 512
Solution #1......................................................................................................................................................... 512
Solution #2......................................................................................................................................................... 512
How It Works...................................................................................................................................................... 512

12-7. Disposing of Producer Fields ...........................................................................................513


Problem ............................................................................................................................................................. 513
Solution.............................................................................................................................................................. 513
How It Works...................................................................................................................................................... 513

12-8. Specifying an Alternative Implementation at Deployment Time ......................................513


Problem ............................................................................................................................................................. 513
Solution.............................................................................................................................................................. 514
How It Works...................................................................................................................................................... 514

12-9. Injecting Bean Metadata ..................................................................................................514


Problem ............................................................................................................................................................. 514
Solution.............................................................................................................................................................. 514
How It Works...................................................................................................................................................... 515

N Chapter 13: Java Message Service ...............................................................................517


13-1. Creating JMS Resources..................................................................................................517
Problem ............................................................................................................................................................. 517
Solution #1......................................................................................................................................................... 518
Solution #2......................................................................................................................................................... 520
How It Works...................................................................................................................................................... 521
13-2. Creating a Session ...........................................................................................................522
Problem ............................................................................................................................................................. 522
Solution.............................................................................................................................................................. 523
How It Works...................................................................................................................................................... 523

xxix
Random documents with unrelated
content Scribd suggests to you:
But the triumph of Juno was short-lived, for Jupiter, from his throne
on Olympus, beheld the founder of the Roman race forgetful of his
destiny and sunk in soft dalliance. He called to him his son Mercury,
and bade him bind on his winged sandals, and bear to Carthage this
stern reproof: "Shame on thee, degenerate hero, false to thy mother
and thy son, thus sunk in luxury and ease! Set sail and leave this
fatal shore."
The heart of the hero, when he heard this message, was torn in
twain. How could he disobey the voice of the god? How could he
bring himself to desert the Queen whose heart he had won, and
break his troth?
But what were the closest of human ties when the god had spoken?
So he called to him his comrades and bade them in secret make
ready the ships for departure. But lovers' ears are keen, and rumors
of the preparation reached the Queen in her palace. She raved like a
madwoman, and called down curses on the perjured traitor. Grown
calmer, she sought Æneas and, with mingled reproaches and
appeals to his pity, besought him at least to delay his departure. The
lover's heart was touched, but the hero was unmoved; and with the
gentlest words he could frame, he told the Queen that he had no
choice but to follow his weird as Heaven ordained. He could never
forget her lovingkindness, and would cherish her memory to his
dying day.
Then the Queen knew that she was betrayed, and flatteries and soft
words served but to rekindle her rage. She bade the perjured wretch
begone; she cursed his false gods and their lying message, and
swore that she would pursue him with black flames, and that after
death her ghost would haunt him in every place. This said, she
turned and left him, and he saw her nevermore.
Æneas would fain have stayed to calm her grief and soothe her
rage, but duty bade him go, and he urged on his men to equip the
fleet for departure. They, nothing loath, set to, and the harbor was
like an ant-hill, with the sailors shaping new oars and loading the
beached vessels. Soon the black keels rode the waters all along the
shore. Dido, perceiving this from her tower, sent her sister Anna with
a last message imploring Æneas yet a little to delay. But Æneas,
steadfast as a rock, turned to her a deaf ear, and into the heart of
the unhappy Dido came despair and thoughts of death.
To death, indeed, dark omens turned her mind. For when she
offered sacrifice, the wine which she poured upon the smoking
incense turned to blood; and at night, when kneeling before the
shrine of her dead husband, she heard his voice bidding her arise
and come to him.
So the Queen, interpreting these dark signs as her sick heart
dictated, made ready to die.
Calling her sister Anna, she declared that she would now make use
of a magic charm given to her by a priestess to bring back faithless
lovers or make the love-sick whole. To work this spell it was
necessary to collect and burn all tokens of the light of love.
"Do you, therefore," said Dido to Anna, "gather together the arms
and garments which Æneas in his haste to be gone has left behind
him, and lay these upon a vast funeral pile, which I beseech you to
erect secretly in the inner court of the palace, under the open sky."
As she spoke, a deadly pallor overspread the face of Dido. But her
sister Anna, suspecting nothing, made haste to obey the Queen. The
great pile was quickly erected, with torches and fagots of oak, and
crowned with funeral boughs. On it were placed the weapons and
raiment of Æneas, while the Queen offered sacrifices, and herbs cut
by moonlight with brazen sickles.
Next morning, before daybreak, Æneas called upon his comrades to
set sail. With his own sword he cut the hawsers, and his men,
pushing off, smote the sounding waves with their oars, and the wind
filling their unfurled sails, they swept out into the open sea as the
sun rose over the waters.
From the tower of her palace Queen Dido saw them depart. And
lifting up her voice she laid a curse upon them, prophesying that for
ages to come dire enmity should rage between the race of Æneas
and the Carthaginian people.
Then, very pale, she entered the inner court and mounted the
funeral pile. A little while she paused, musing and shedding her last
tears.
Anon she spoke, and bade farewell to the light of the sun: "I have
lived my life; I have finished the course ordained to me by Fate. I
have raised a glorious city. I descend illustrious to the shades
below."
She paused, and her voice fell to a low wail as she added: "Happy,
ah, too happy, my lot had the Trojan ships never touched my
shores!"
Then, unsheathing the sword, she plunged it into her bosom and fell
down upon the pyre.
Her handmaidens, seeing her fall, rent the air with their cries. And
Anna, rushing in, raised her dying sister in her arms, striving in vain
to stanch the flowing blood, and crying with tears: "Oh, sister, was it
for this that you bade me raise the pyre? Ah, would that you had let
me be your companion in death!"
But the last words of Dido, Queen of Carthage, had been spoken.

Far out at sea, Æneas saw a great smoke rising from Carthage, as it
were from a funeral pyre. And a sore pang smote him, and bitterly
he divined what had passed. But he held upon his destined way, nor
looked he back again, but turned his eyes towards the promised land
of Latium.
ÆNEAS IN HADES
BY V. C. TURNBULL

"The journey down to the abyss


Is prosperous and light;
The palace gates of gloomy Dis
Stand open day and night;
But upward to retrace the way,
And pass into the light of day,—
There comes the stress of labor—this
May task a hero's might."

Virgil.—Conington's Translation.
Æneas, in the course of his wanderings, landed on the shores of
Cumæ in Italy. Here he sought out the Sibyl, the inspired prophetess
who dwelt in a cave behind the temple of Apollo, and gave forth to
inquirers the answers of the god. High destinies she promised
Æneas, but not without many further trials.
Æneas, undismayed, besought the Sibyl to guide him on his way: "O
Priestess, it has been told that here are the gates of the lower world.
Open for me, I beg of you, that portal, for I long greatly to speak
once more with my dear father. I bore him on my shoulders from
flaming Troy, and in all my voyages he accompanied me, facing,
though infirm, the terrors of sea and sky. Nay, more, it was at his
bidding that I came a suppliant to thy temple. Have pity upon us
both, O Sybil, and enable us to meet once more."
Then the Sibyl, in reply, warned Æneas that though many went
down with ease into the Abode of the Dead, few—very few, and they
the specially favored of the gods—returned therefrom. "But if," she
went on, "you are determined to dare the desperate enterprise, seek
out in this dark wood a tree that hides one branch all golden. This
bough is sacred to Proserpine, Queen of the Lower World, and to her
must you bear it as a gift. Without it no living being may enter the
Lower World. Pluck it, and if the Fates have willed it so, it will yield
at a touch, else no mortal force can wrest it from its parent stem."
So Æneas and Achates plunged into the primeval forest near which
the Sibyl dwelt. They had not gone far when two doves alighted on
the sward hard by. Then Æneas was glad, for he knew them to be
the birds of his mother Venus, and he besought his mother that her
messengers might guide him on his way. And the doves flitted on
before them till they lighted at last on a lofty tree, amid the boughs
of which Æneas discerned the gleam of gold. This was the Golden
Bough, growing like mistletoe from the oak, and there was a tinkle in
the air as the breeze rustled the golden foil. Joyfully Æneas broke it
from the trunk, and bore it back to the dwelling of the Sibyl.
Then the priestess led the way back into the gloomy wood, halting
before a cavern, vast and hideous with its yawning black mouth,
from which exhaled so poisonous a breath that no bird could cross it
unhurt. Here Æneas and the Sibyl offered sacrifices to the Gods of
the Lower World. At sunrise the ground began to rumble beneath
their feet, and a baying of hell-dogs rolled up from the chasm.
"Avaunt, ye profane!" cried the priestess, "and, Æneas, do thou
draw thy sword and march boldly forward; now is the hour to try thy
mettle."
So saying, she plunged into the dark cavern, and Æneas, following,
entered the world of the dead.
In a desolate country on the outskirts of the spirit-world they saw
the forms of Grief and vengeful Cares; here dwelt disconsolate Old
Age, Fear, Famine, Death, and Toil. Murderous War was here, and
frantic Discord, whose viperous locks are bound with bloody fillets.
All these they passed, coming to the turbid flood Acheron, on which
the ferryman Charon, a grisly, unkempt graybeard, with eyes of
flame, plied to and fro.
On the banks of the river stood a great company of ghosts, matrons
and men, boys and maidens, numerous as swallows flying south, or
leaves before the autumn wind. They stood praying to be taken into
the boat, and stretching their hands towards the farther shore; but
the sullen boatman would take only a few, choosing whom he
would. Then, in reply to his questions, the priestess told Æneas that
the bodies of those whom the boatman refused had been left
unburied upon earth, wherefore these ghosts were doomed to flutter
for a hundred years along the shores of Acheron before Charon
would consent to ferry them across.
By this time they had reached the landing-stage, and the priestess
beckoned to Charon; he refusing at first to carry a mortal across that
river till she showed him the Golden Bough. At the sight of this
Charon came at once with his boat, pushing out the ghosts that sat
therein to make room for Æneas. Groaning beneath the weight of a
mortal the boat was well-nigh swamped, but at length the priestess
and the hero were safely landed on the farther shore.
But now at the gate stood Cerberus, the three-headed dog, making
those realms resound with his barking. To him the priestess threw an
opiate of honey-cakes, and he, snatching at it with his three mouths,
lay down to sleep, thus permitting them to pass.
Now to their ears came the wails of infants, ghosts of those who had
been bereft of sweet life even at their mother's breast. Next came
those who had been condemned to death unheard or falsely
charged. Full justice they now received; Minos the judge metes out
to each his proper sentence.
After these Æneas came upon a group of those unhappy ones who
with their own hands had destroyed their lives. Ah, gladly now would
they endure poverty and toil could they but revisit the kindly light of
the sun!
Now Æneas entered a region named the Fields of Mourning,
inhabited by the ghosts of those who had died for love. And among
them, in a wood, Æneas saw, or deemed he saw, dim as the new
moon in a cloudy sky, the form of Dido, still pale from her death-
wound. Tears in his eyes, he addressed her sad ghost with loving
words as of old: "So, as I feared, it was true, the message of those
funeral fires. And was I, alas! the cause of your death? O Queen,
believe that it was against my will that I left thy coasts! Unwilling, I
swear, by the behest of the gods did I leave thee, even as now, by
the same behest, I tread the land of darkness and despair. Ah, tarry
but a little! 'Tis our last farewell."
ÆNEAS IN HADES

So he spoke, seeking to soothe the injured shade. But she, with


averted eyes, stood still as a statue of stone. Then in silent scorn
she fled to seek her first lord, Sichæus, who answers sorrow with
sorrow.
Thence to the farthest fields they passed the haunts of heroes slain
in battle; and here Æneas greeted many comrades of early days. But
when the ghosts of Agamemnon's Greek army beheld the mighty
hero, his arms gleaming through the shades, they quaked, and many
fled as erstwhile before to their ships, while others, trying to raise
the war-cry, could utter only "the bat-like shrilling of the dead."
A pitiful shade, with marred visage and mangled body, approached
them, and Æneas recognized the ghost of Deiphobus, son of Priam,
and asked of his cruel fate; and Deiphobus poured forth the long
tale of his wife's treachery, and how he had been foully slaughtered
in his sleep. Long had they thus conversed, but the Sibyl plucked
Æneas by the robe and warned him: "Night falls apace; 'tis time to
go. Thou hast come to the parting of the ways. Here lie Elysium and
the fields of the blessed, and there, to the left, Tartarus and the
tortures of the damned." And even now Æneas descried vast prisons
inclosed with a triple wall, round which the river Phlegethon rolled its
threefold floods of flame, while rocks whirled roaring down the
stream. Over against the stream stood a massive gateway, whose
adamantine columns defied all force of men or gods, and above the
gate rose a tower of iron. Here sat the Fury Tisiphone, watching all
who entered. And from within the gate came groans and the
whistling of scourges and the clanking of chains.
Æneas asked what meant this woful wailing, and the Sibyl replied:
"None innocent may cross that threshold. There Rhadamanthus
judges the dead, and avenging Tisiphone scourges the guilty. Within
the gate rages the Hydra with fifty gaping mouths. Downward sinks
the pit, twice as deep as the heavens are high. In it groan the
Titans, hurled down with thunderbolts, and the giants, Otus and
Ephialtes, who strove to overturn the throne of Jupiter himself.
There lies Tityus, o'er nine roods outstretched, and eternally does a
vulture tear his liver with her beak. Over some hangs a rock
threatening ever to fall; before others a bounteous banquet is
continually spread, but the hands that they stretch to take the food
are evermore struck back by the Furies. Some roll a huge stone,
others are bound to the revolving wheel. Here lie they who heaped
up riches for themselves, an unnumbered multitude; here also they
who hated their brothers or lifted cruel hands against their parents.
Take warning by their fate, and ask no further concerning their awful
doom."
Thus warned, Æneas went forward in silence, and at the direction of
the Sibyl he offered the Golden Bough at the gate.
Now came they at length to the regions of joy, the green retreats
and happy groves of Elysium. An ampler ether and a purer light
invest these fields, for the blessed have their own sun and stars. In
jousts and races, in dance and song, they fleet the golden hours, a
blessed company of bards and patriots, paladins and victors in the
races. Among them Æneas marked Ilus, a former king of Troy, and
Dardanus, that city's founder. Their chariots were empty, their spears
stood fixed in the ground, their horses fed at large throughout the
plain, for the ruling purpose in life survives the grave.
There, in a sequestered dale, stood Anchises surveying the souls
that were to revisit earth once more, among them his own offspring
yet unborn. But when he saw Æneas moving to meet him, with
outstretched arms and tearful eyes he cried: "O my son, my son,
hast thou come to me indeed? Am I permitted to see thy face and
hear thy well-known voice once more?" And Æneas answered,
weeping also: "Give me thy hand, my father, and take me to thy
breast." Thrice he strove to throw his arm round his father, thrice the
phantom slipped from his embrace, thin as the fluttering breeze or
like a dream of the night. Gazing around him he saw in a wooded
glade numberless peoples and tribes, hovering above the brakes like
bees in summer-time, and he inquired of his sire what these might
be.
Then Anchises taught Æneas many wonderful things concerning the
state of departed souls in Elysium and the future of the Trojan race.
And touching the first, he said that after suffering many things the
evil of their natures was washed or burned away, and they passed to
Elysium, there to dwell for a thousand years. "All these," he
continued, "are then summoned forth by the gods in a great body to
the river Lethe, wherein they leave all memory of the past and again
become willing to return into mortal bodies."
Saying this, he led Æneas to the summit of a hill from which they
who were to be born could be seen passing in an endless file before
them.
"See you," he said, "that youth leaning on a pointless spear? He
shall be Silvius, the child of thy old age, and shall reign over Alba
Longa. Behold there Romulus, the founder of Rome, the city of the
seven hills, he shall rule the world. The graybeard behind him is
Numa, the lawgiver, and next comes Tullus, the warrior. Those that
follow are the proud Tarquins. There, too, is Brutus, unhappy man,
who shall give liberty to Rome; and, unhappy father! whose
inflexible justice shall doom to death his guilty sons."
All these and many others who sprang from Æneas' loins, did
Anchises point out, crying as he ended: "To you, O Romans, be it
given to rule the nations, to dictate terms of peace, to spare the
humbled, and to crush the proud."
Last they watched the great Marcellus, the terror of the Gauls, the
conqueror of Carthage.
Then Æneas asked: "What youth is he, O father, who walks by his
side in shining armor; but his countenance is sad, his eyes fixed
upon the ground? Is he a son, or haply a grandson?"
And Anchises wept as he replied: "Alas, my son, for the sorrows of
thy kindred! Dear child of pity! could'st thou but burst thy fate's
invidious bar, our own Marcellus thou! Ah! woful shall be the day of
his death! Could he but live none had faced his onset. Bring lilies—
lilies in handfuls; let me heap bright flowers on the shade unborn,
and pay at least this empty tribute."[1]
Thus they passed through Elysium, Anchises showing and explaining
all to Æneas, firing him with the thoughts of future fame, and
instructing him how to act throughout the struggles of his remaining
life. Then, when all had been shown and said, Father Anchises sent
back his son Æneas and the Sibyl to the mortal world by that shining
Ivory Gate where through pass the dreams that visit the slumbers of
men.
NISUS AND EURYALUS
BY F. STORR
Æneas was absent from the camp. Warned by Father Tiber he had
gone with a picked band of followers to seek the alliance of his
kinsman, King Evander, who with his Arcadians had settled
themselves on the seven hills which now are Rome.
Whilst he was away, the camp was left in charge of his son Iulus,
and as adjutant and counselor to the young prince he appointed his
most experienced general, old Aletes.
But Juno, the implacable foe of Troy, had despatched to Turnus, the
Rutulian Prince, her messenger Iris to tell him of Æneas' absence
and bid him seize the occasion to storm the Trojan camp. So all day
long the garrison, reduced in numbers and without its great captain,
saw the tide of horse and foot, Latins, Rutulians, and Etruscans,
gathering in the plain and sweeping onward to overwhelm them, like
the Nile in full flood. As Æneas had bid them, they retired within
their intrenchments, too strong to be carried at the first assault.
At nightfall the enemy withdrew, and the weary defenders lay down
to sleep, but in fear of a night attack they ventured not to unbuckle
their armor, and at each camp-gate was posted a strong guard of
sentinels.
Conspicuous among the captains of the guard was Nisus, whom his
mother, Ida, the world-famed huntress, had sent as squire to Æneas,
no less skilled than his mother with javelin or with bow. With him as
his lieutenant was Euryalus, the fairest youth, save Iulus alone, in all
the Trojan host, the down of manhood just showing on his cheek,
elsewise as round and smooth as a girl's.
The two were more than brothers-in-arms, inseparable as twin
cherries on a single stalk; the one followed the other as his shadow,
and their love was more than the love of man and maid.
And now as they kept watch together they thus conversed:
Nisus. I know not what ails me, brother, but to-night I feel a wild
unrest, a strange prompting to be up and doing some doughty deed.
What think you, brother? Is it an inspiration of heaven or only my
own fiery spirit, pent up within these walls and fretting for the fray?
Mark you, brother. The enemy's camp is silent as the tomb. Not a
sentinel is stirring, and the rare watch-fires burn low. 'Tis plain to me
that the captains, having driven us back to our trenches, have been
celebrating their victory and are now buried in drunken slumber.
Now I will expound to thee the plan that is working in my brain. At
all hazards Æneas must be summoned back from the city of Evander
—so our generals and men are all agreed. If only my proposal is
accepted, methinks I have discovered a way to bear the message
and work our deliverance.
Euryalus. Verily 'tis a glorious venture and well worth the risk, but
thou speakest as if the venture were thine. Can I have heard thee
aright? Truly, brother, the plan is thine, but the execution is ours.
Thinkest thou, brother, alone to put thy head into the lion's mouth?
Shall I not share thy triumph or thy death? In life we have been one,
and in death we shall not be divided.
Nisus. Nay, brother, I never doubted thy courage or thy love. This
thought alone, perhaps a selfish thought, was mine: if perchance I
should fall—and sanguine as I am of success I know 'tis a perilous
hazard—I would fain one sure friend survived to lay my body in
mother earth, or if that grace is denied, at least to perform due rites
at my cenotaph. I thought, moreover, that thou art the younger man
and thy mother's only son.
Euryalus. Out on thy vain excuses! Only if thou takest me with thee
will I forgive them. My mind is set. Let us to work.
So they called to the nearest sentinels to relieve them of their guard
and hurried to seek Iulus. They found him in his tent presiding over
a council of war, but the sentries let them pass on business that
would not wait. It chanced that the captains were at that moment
debating how possibly to convey a message to Æneas informing him
of their pressing need, and when Nisus expounded to them his plan,
assuring them that as a young hunter he had explored every inch of
the ground and knew a secret forest path that would lead them to
the rear of the enemy's camp, he was welcomed as a messenger
sent from heaven. Old Aletes laid his hands on their heads and with
tears in his eyes blessed the gods for sending such deliverers.
"Young heroes!" he cried, "your virtue is its own reward, but Æneas,
when he returns, will know how to recompense you." Iulus, with
boyish generosity, promised them his choicest treasures, embossed
tankards and two talents of gold, aye and the charger and arms of
Turnus, whose fall was certain when Æneas returned; and he put his
arms round Euryalus' neck (the youth was scarce older than himself)
and called him his brother-in-arms.
Boldened by this signal favor of the prince, Euryalus, on bended
knee, besought one parting boon. "Prince," he cried, "I have an
aged mother who for my sake left her native home and the court of
King Acestes to accompany me to the wars. I may not stay to bid
her farewell and receive her blessing, nor could I dare confide to her
our perilous errand. Thou hast deigned to call me brother: O prince,
be to her a son. To know that thou wilt be here to solace and
comfort her will give me fresh confidence." The prince swore to love
and cherish her no less than his own lost mother, Creusa, and
wishing him Godspeed he girt on his shoulder the sword of that
famous Cretan swordsman, Lycaon, with hilt of wrought gold and
scabbard of ivory. To Nisus, Achates gave his own helmet, that had
borne the brunt of many a shrewd blow.
Thus armed and charged with many messages from Iulus to his
father they left the camp, and the captains sent after them a parting
cheer.
The night was dark, but Nisus could almost have found his way
blindfolded through the familiar forest. In a short hour they had
reached the camp unperceived, and then, as Nisus had anticipated,
they found a scene of barbarous revelry. Amongst tilted war-
chariots, tethered horses, and empty wine-jars men lay stretched in
drunken slumber.
"Follow me," whispered Nisus, "and keep an open eye lest any
attack me from behind. I will hew thee anon a path of blood by
which we can both pass to our goal."
With drawn sword he rushed on Rhamnes, who lay snoring on a pile
of broidered coverlets: an augur was he of royal blood, but little did
his augury avail him that day. His three attendants soon followed
their master to the shades. Like a ravening wolf who has leapt into
the sheepfold he dealt havoc right and left, and all that Nisus spared
the sword of Euryalus despatched.
"Enough," cried Nisus, at length sated with carnage; "our way
through the enemy is clear, and the tell-tale morn is nigh at hand."
Much rich spoil they left behind—flagons of gold and silver, gemmed
goblets and broideries; but Euryalus cast longing eyes on a huge
baldrick with bosses of gold, an heirloom of the dead augur, and he
strapped it round his shoulder; nor could he resist (proud youth) the
temptation to try on a bright helmet with flaming crest of Messapus,
the Tamer of Steeds. With these spoils to attest their glorious raid,
the pair left the camp and gained in safety the open.
Their task seemed well-nigh accomplished, but it chanced that a
troop of three hundred horse, despatched from the Latin capital as
an advanced guard for Turnus, were just then approaching the camp
from the opposite direction, and espying in the twilight the glint of
the helmet they challenged the pair. No answer was returned, and
Nisus, who was leading, quickened his pace to gain the shelter of
the forest. The horsemen wheeled round and sought to cut off their
retreat, but they were too late, and Nisus was already speeding
down a winding bypath that he knew full well, when he looked back,
and to his horror perceived that Euryalus was not following.
"Euryalus!" he shouted, but no answer came. He turned and
painfully retraced his steps. Soon he heard the tramp of horses
among the brushwood and broken branches, and guided by the
sound in a clearing of the forest he saw Euryalus, his back against
an oak, like a stag at bay, facing a ring of horsemen. What was he to
do? To save himself by flight was unthinkable, but should he rush at
once on certain death? In desperation he breathed a prayer to his
patron goddess Diana. "Queen of the woods," he cried, "by the gifts
I have offered on thine altar, by the vows I have daily paid, help me
now in my utmost need and guide my aim!" So praying, he hurled
with all his might a spear, and so straight and swift it flew that
Sulmo was transfixed from back to breast, and the shaft snapped off
short as the barbed head quivered in the wound. A second spear
buried itself in Tagus's brain, and he too bit the dust. Volscens, the
captain of the troop, saw his two comrades struck down as by a bolt
from the blue, and with drawn sword he turned on Euryalus crying,
"If I cannot reach the fiend who hurled those spears, thy blood at
least shall atone the bloody deed."
At this Nisus could no longer restrain himself, and leaping from the
covert he shouted, "I, none but I, am the guilty cause. Oh, spare
this innocent boy and turn your swords on me! To love his friend too
well, this was his only crime!" But his words were vain; while yet he
spoke the sword of Volscens had pierced the boy's heart and stained
with gore his white side, and he drooped his head like a poppy
drenched with rain, or a harebell upturned by the plowshare.
At the sight Nisus hurled himself into the thick of his foes, scattering
them right and left with the lightnings of his glaive, till he forced his
way to Volscens, and with a dying effort smote the murderer of his
sweet friend. Pierced with a hundred wounds he fell upon Euryalus'
prostrate corpse, and a smile was on his lips, for in death they were
not divided.
Such was the tale that Virgil sang, and the prophecy that he uttered
nigh upon two thousand years ago has been fulfilled:
"O happy pair, if aught my verse avail,
Your memory through the ages shall not fail,
While on the Capitol Rome's flag is seen
And Rome holds sway, Italia's Empress Queen."
ULYSSES IN HADES
BY M. M. BIRD
Before he left fair Circe's isle Ulysses reminded the goddess of her
promise to speed them on their homeward way. This, she assured
him, not she but the Fates refused. Nor could they hope to breathe
their native air till a long and toilsome journey had been taken, a
journey that would lead them down even to the dread realms of
Death. "But there," she said, "you shall seek out blind Tiresias, the
Theban bard; though his eyes be blind his mind is filled with
prophetic light. He will tell you all you seek to know of your future
and the fate of those you love."
Brave as he was, Ulysses shuddered at the awful road he had to
tread, and appealed to Circe for further aid in this adventure. So she
told him the landmarks to guide him on his way, and instructed him
what to do when he reached the realms of Tartarus. And when morn
broke he summoned his companions to set forth. They came in
haste and joy.
But one was missing. Elpenor, the youngest of the band, a wild and
senseless youth, had climbed to the housetop to breathe the cold air
after a debauch lasting far into the night. At the sudden tumult of
departure he was roused, and hastening down he missed the ladder
and fell headlong from the roof and broke his neck.
Ignorant of his fate, the rest crowded eagerly round their leader, till
his few and sober words told them that not yet the joys of
homecoming awaited them, but it was decreed that first they should
seek the awful shade of Tiresias in the dark and dreary realms of
Death. Sadly then upon that shore they made their sacrifices to the
immortal gods, and sadly embarked in the waiting ship and spread
their sails to the freshening breeze.
As the sun sank, and all the ways were darkened, they reached the
utmost bounds of Ocean, a lonely land, where the sun never shines,
where darkness broods perpetually over bare and rocky crags, the
abode of the Cimmerians. Off their desolate shore Ulysses cast
anchor, and leaping from his ship, descried the awful chasm that
leads to the realms of the dead.
His two companions bore with them the black sheep as Circe had
bidden, and Ulysses drew his shining sword and carved a great
trench, a cubit long and wide, in the black earth. This was filled with
wine, milk, and honey, and the blood of the newly offered sacrifices.
Thus, with solemn rites and holy vows, they invoked the nations of
the dead. And lo! among the frowning caverns and all along the
dusky shores appeared the phantom shapes of unsubstantial ghosts.
Old and young, warriors ghastly with wounds, matrons and maids,
rich and poor, they crowded about the trench filled with the reeking
blood of sacrifice. But Ulysses in terror brandished his sword above
the flowing blood, and the pale throngs started back and stood
silently about him.
Then he saw Elpenor, new to the realms of Death. Astonished, he
demanded of the shade how it was that he had outrun their swift
sail, and was found wandering with the dead. To which the youth
replied that his feet, unsteady through excess of wine, had betrayed
him and sent him headlong from the tower, and as he fell his neck
was broken and his soul plunged in Hell.
But he implored Ulysses, by all he held most dear, to give his
unburied limbs a peaceful grave, and set up a barrow, and on it
plant his oar to show that he had been one of Ulysses' crew. And
Ulysses granted the boon, and the spirit of Elpenor departed
content.
Then, as Ulysses sat watching the trench, he saw the shade of his
royal mother, Anticlea, approach; but though the tears bedewed his
cheek at the sight, the pale shade stood regardless of her son.
Next came the mighty Theban, Tiresias, bearing a scepter of gold;
and he knew him and spake: "Why, son of Laertes, wanderest thou
from cheerful day to tread this sorrowful path? What angry gods
have led thee, alive, to be companion of the dead? If thou wilt
sheathe thy sword I will relate thy future and the high purposes of
Heaven towards thee."
Ulysses sheathed his glittering blade, and the seer bent down and
drank of the dark blood. Then he foretold all the strange disasters
that would threaten and detain Ulysses on his homeward way. He
told how at length he alone of all his crew would survive to reach his
country—there to find his labors not yet at an end, with foes in
power at his court, lordly suitors besieging his wife, and wasting his
substance in riot and debauch. But a peaceful end to his long and
toilsome life should come at last, and see him sink to the grave
blessed by all his people. "This is thy life to come, and this is Fate,"
said the seer.
To whom Ulysses, unmoved, made answer: "All that the gods ordain
the wise endure."
So the prophet went his way, and Ulysses waited on for his mother
to come. And anon, Anticlea came and stooped and drank of the
dark blood, and straightway all the mother in her soul awoke, and
she addressed her son, asking whence he came and why.
"To seek Tiresias, and learn my doom," Ulysses answered, "for I
have been a roamer and an exile from home ever since the fall of
Troy." Then he asked her how her own death had happened,
whether his good father Laertes still lived, if Telemachus his son
ruled in Ithaca, and if Penelope yet waited and watched for her
absent lord, or if she had taken a new mate.
To all his questions Anticlea made answer with tender pity. Penelope,
his faithful wife, still mourned for him uncomforted; Telemachus,
now almost grown to manhood, ruled his realm; and old Laertes,
bowed with grief, only waited in sorrow for the release of the tomb,
since his son Ulysses returned no more. She herself, his mother, had
died of a broken heart; for him she lived, and when he came not, for
love of him she died.
Ulysses, deeply moved, strove thrice to clasp her in his arms, and
thrice she slipped from his embrace, like a shadow or a dream. In
vain he begged that his fond arms might enfold the parent so
tenderly loved, that he might know it was she herself and no empty
image sent by Hell's queen to mock his sorrow. But the pensive
ghost admonished him that such were all spirits when they had quit
their mortal bodies. No substance of the man remained, said she: all
had been devoured by the funeral flames and scattered by the winds
to the empty air. It was but the soul that flew, like a dream, to the
infernal regions. "But go," she adjured him; "haste to climb the
steep ascent; regain the day and seek your bride, to recount to her
the horrors and the laws of Hell."
As she ceased and disappeared, a cloud of phantoms, wives and
daughters of kings and heroes, flitted round the visitant of earth.
Dauntless he waved his sword; the ghostly crew shrank away and
dared not drink of the wine in the trench at his feet. They passed,
and to each other Ulysses heard them recount their names and
needs. There he saw Alcmena, mother of Alcides; Megara, wife of
Hercules, who was slain by him in his madness; the beautiful Chloris,
Antiope, and Leda, mother of the deathless twins Castor and Pollux,
who live and die alternately, the one in Heaven and the other in Hell,
the favored sons of Jove.
There walked Phædra, shedding unceasing tears of remorse for her
slain love, and near her mournful Ariadne. All these, and many more,
Ulysses recognized in that pale procession of departed spirits. When
they had been summoned back to the black halls of Proserpine, the
forms of the heroes slain by the foul Ægisthus came in sight. High
above them all towered great Agamemnon. He drank the wine and
knew his friend; with tears Ulysses greeted him and inquired what
relentless doom, what fate of war, or mischance upon the ocean,
had thrust his spirit into Hell? And Agamemnon told him all the
dreadful story of his return from Troy, and the treachery of his wife
Clytemnestra and her lover, who slew him as he feasted, and with
him all his friends; most pitiful of all, the voice of the dying
Cassandra, slain at his side as he himself lay dying, still rang in his
ears.
And Ulysses answered him: "What ills hath Jupiter wreaked on the
house of Atreus through the counsels of women!"
"Be warned," replied Agamemnon, "and tell no woman all that is in
thy heart; not even Penelope, though she is discreet and true above
all other women and will not plot thy death." And he grieved for his
own son Orestes, on whom he had never looked, envying his friend
an heir so wise and brave as the young Telemachus.
Then he saw Achilles and Patroclus, approaching through the gloom.
Achilles knew his friend and hastened to his side. "Oh mortal,
overbold," he asked, "how durst thou come down living to the
realms of the dead?" Ulysses told him how he had come, though
living, to seek counsel of the dead.
But Achilles made answer:

"Rather would I, in the sun's warmth divine,


Moil as a churl, who drags his days in grief,
Than the whole lordship of the dead were mine."

Then, like Agamemnon, he demanded news of his son, and Ulysses


charmed the father's heart by telling of the gallant deeds of
Neoptolemus at Troy town, and how he had escaped unscathed from
the fight.
Achilles glowed with pride and delight; and as he joined the
illustrious shades of the warriors about him, Ulysses sought the side
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like