Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From...

17
Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media, LLC

Transcript of Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From...

Page 1: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Beginning J2EE 1.4:

From Novice to Professional

James L. Weaver, Kevin Mukhar, andJim Crume

APress Media, LLC

Page 2: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Beginning J2EE 1.4: From Novice to Professional Copyright © 2004 by Apress

Originally published by James L. Weaver, Kevin Mukhare, and Jim Crume in 2004.

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanica!, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN 978-1-59059-341-7 ISBN 978-1-4302-0716-0 (eBook) DOI 10.1007/978-1-4302-0716-0

Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

Additional Material: Rick Leander, Jim MacIntosh, Ron Phillips, AndrewWatt

Technical Reviewers: James L. Weaver, Kevin Mukhar, }im Crume, Tom Marrs, Steve Anglin

Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan HasseI!, Chris Mills, Dominic Shakeshaft, }im Sums er

Assistant Publisher: Grace Wong

Project Manager: Kylie Johnston

Copy Editor: Ami Knox

Production Manager: Kari Brooks

Production Editor: KellyWinquist

Proofreader: Katie M. Stence

Compositor: Katy Freer

Indexer: John Collin

Artist: April Milne

Cover Designer: Kurt Krames

Manufacturing Manager: 'Ibm Debolski

Distributed to the book trade in the United States by Springer-Verlag NewYork, Inc., 233 Spring Street, 6th Floor, NewYork, NY 10013, and outside the United States by Springer-Verlag GmbH & Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany.

In the United States: phone I-BOO-SPRINGER, email [email protected], or visit http://www . springer­ny. com. Outside the United Stales: fax +49 6221 345229, email [email protected], or visit http://www.springer.de.

The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or darnage caused or alleged to be caused directly or indirectly by the information contained in this work.

The source code for this book is available to readers at http://www . apre55. cam in the Source Code section.

Page 3: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents at a Glance

Foreword Xl

Introduction XV

Chapter 1: J2EE Essentials 1

Chapter 2: Getting Set 25

Chapter 3 : JavaServer Pages 45

Chapter 4: AdvancedJSP Topics 99

Chapter 5: Servlets 151

Chapter 6: Working with Databases 221

Chapter 7: Advanced Topics inJDBC 259

Chapter 8: EJB Fundamentals 311

Chapter 9: EJB Entity Beans 343

Chapter 10: More EJB Topics 399

Chapter 11: Design Patterns and Message-Driven Beans 437

Chapter 12: Web Services andJAX-RPC 481

Chapter 13: MoreJ2EE Web Services Topics 511

Appendix A: Installing Tomcat 543

Appendix B: SQL and EJB-QL 547

Appendix C: J2EE Glossary 569

Index 575

Page 4: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents

Foreword xi

Introduction xv

Chapter 1: J2EE Essentials 1

What Is J2EE? ...................................................................................................................... 2 How J2EE Relates to J2SE ............................................................................................ 2 Why J2EE? ...................................................................................................................... 3

Features and Concepts inJ2EE ........................................................................................ 10 Containers .................................................................................................................... 11 Java Servlets .................................................................................................................. 12 JavaServer Pages .......................................................................................................... 14 Enterprise J avaBeans .................................................................................................... 16 XML Support ................................................................................................................ 18 Web Services ................................................................................................................ 19 Transaction Support .................................................................................................... 19 Security .......................................................................................................................... 20

SampIe J2EE Architectures ................................................................................................ 20 n-Tier Architecture ...................................................................................................... 21 Application Client with EJB ........................................................................................ 21 JSP Client with EJB ...................................................................................................... 22 Applet Client withJSP and Database ........................................................................ 22 Using Web Services far Application Integration ...................................................... 23

Summary .............................................................................................................................. 23

Page 5: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents

Chapter 2: Getting Set 25

Installing the j2EE 1.4 SDK .............................................................................................. 26 Problems and Solutions .............................................................................................. 26

Testing thej2EE 1.4 SDK Installation ............................................................................ 29 Starting the Database Server ...................................................................................... 29 Starting the j2EE Server .............................................................................................. 31 Problems and Solutions .............................................................................................. 32

Compiling and Deploying "Hello j2EE W orld" ............................................................ 33 Problems and Solutions .............................................................................................. ,12

Summary ............................................................................................................................. .43

Chapter 3: JavaServer Pages 45

Introduction to jSP ............................................................................................................ 45 DevelopingjSP Pages ................................................................................................. .46 Basic jSP Lifecycle ........................................................................................................ 46

WritingjSP Pages .............................................................................................................. 47 jSP Elements ............................................................................................................... .48 Implicit Objects ............................................................................................................ 69 Scope .............................................................................................................................. 73

Translation and Compilation ............................................................................................ 81 The Servlet API ............................................................................................................ 82 The jSP API .................................................................................................................. 82 A TranslatedjSP .......................................................................................................... 82

Errors and Exceptions ........................................................................................................ 84 The page Directive ...................................................................................................... 85 The Deployment Descriptor ...................................................................................... 85

Including and Forwarding from jSP Pages ...................................................................... 91 include Action .............................................................................................................. 91 forward Action .............................................................................................................. 91 Using include and forward .......................................................................................... 92

Summary .............................................................................................................................. 97 Exercises .............................................................................................................................. 98

Chapter 4: Advanced JSP Topics 99

Expression Language ........................................................................................................ l 00 Syntax of EL .............................................................................................................. 101 Implicit Objects .......................................................................................................... 1 04 U sing EL Expressions ................................................................................................ 1 06

Custom Actions and Tag Libraries ................................................................................ 114 Custom Actions .......................................................................................................... 115 Tag Handlers .............................................................................................................. 116 Simple Tag Handlers ................................................................................................ 116 Tag Library Descriptor .............................................................................................. 118

vi

Page 6: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents

Packaging Tag Libraries ............................................................................................ 121 JavaServer Pages Standard Tag Library aSTL) ............................................................ 140

Getting an Implementation ...................................................................................... 140 What's in theJSTL? .................................................................................................. 140 Core Actions .............................................................................................................. 141 Formatting Actions .................................................................................................... 142 SQL Actions ................................................................................................................ 143

Other Tag Libraries .......................................................................................................... 148 Summary ............................................................................................................................ 149 Exercises ............................................................................................................................ 149

Chapter 5: Servlets 151

HTTP and Server Programs ............................................................................................ 152 Request Methods ........................................................................................................ 152

The Servlet Model and HttpServlets .............................................................................. 157 Basic Servlet Design .................................................................................................. 158 Using the request Object .......................................................................................... 167 Using the response Object ........................................................................................ 169 Deployment Descriptors ............................................................................................ 170 Servlet Lifecycle .......................................................................................................... 174 Event Logging in Servlets .......................................................................................... 178 Servlets Are Multi-Threaded .................................................................................... 178

Handling Exceptions ........................................................................................................ 186 Poor Exception Handling .......................................................................................... 186 Error Pages .................................................................................................................. 187

Session Management ........................................................................................................ 188 Session Management with Cookies .......................................................................... 191

Filters .................................................................................................................................. 1 96 Why You Need Filters .............................................................................................. 196 Implementing a Filter ................................................................................................ 197

The MVC Architecture .................................................................................................... 205 Model 1 vs. Model 2 .................................................................................................. 205 MVC ............................................................................................................................ 206 Forwarding and Including Requests ........................................................................ 207

Summary ............................................................................................................................ 219 Exercises ............................................................................................................................ 220

vii

Page 7: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents

Chapter 6: Working with Databases 221

Connecting to Databases .................................................................................................. 222 Drivers ........................................................................................................................ 223 Driver Types .............................................................................................................. 223 The DriverManager Class ........................................................................................ 226 Loading a Driver ........................................................................................................ 226 Connections ................................................................................................................ 228

Statements .......................................................................................................................... 238 Creating and Using Statement Objects .................................................................... 238

Resultsets ............................................................................................................................ 246 Summary ............................................................................................................................ 257 Exercises ............................................................................................................................ 25 7

Chapter 7: Advanced Topics in JDBC 259

Prepared Statements ........................................................................................................ 260 Creating a Prepared Statement ................................................................................ 262 Using a Prepared Statement ...................................................................................... 263

Callable Statements .......................................................................................................... 267 Using Placeholders .................................................................................................... 269

Data Sources and Connection Pools .............................................................................. 271 Data Source Overview .............................................................................................. 271 Using a DataSource Object ...................................................................................... 272 Connection Pool Overview ...................................................................................... 273

Transactions ...................................................................................................................... 282 Connection Methods for Transaction Contrai ........................................................ 284 Transactions and Stored Pracedures ........................................................................ 286 Intraduction to Distributed Transactions ................................................................ 292

Locking and Isolation ...................................................................................................... 295 Pessimistic Locking .................................................................................................... 297 Optimistic Locking .................................................................................................... 304

Summary ............................................................................................................................ 309 Exercises ............................................................................................................................ 31 0

Chapter 8: EJB Fundamentals 311

Understanding EJBs .......................................................................................................... 312 Why Use EJBs? .......................................................................................................... 312 The Three Kinds ofEJBs .......................................................................................... 314 Decisions, Decisions .................................................................................................. 316

A Closer Look at Session Beans ...................................................................................... 316 The Anatomy of a Session Bean .............................................................................. 317 Developing Session Beans ........................................................................................ 318 Stateful vs. Stateless Session Beans .......................................................................... 334

Summary ............................................................................................................................ 341 Exercises ............................................................................................................................ 342

viii

Page 8: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents

Chapter 9: EJB Entity Beans 343

A Closer Look at Entity Beans ........................................................................................ 344 The Anatomy of an Entity Bean .............................................................................. 344 Other Features of Entity Beans ................................................................................ 347

Developing CMP Entity Beans ...................................................................................... 349 Developing BMP Entity Beans ........................................................................................ 368

EJB Local Interfaces .................................................................................................. 376 The EJB Query Language ........................................................................................ 387

Summary ............................................................................................................................ 397 Exercises ............................................................................................................................ 398

Chapter 10: More EJB Topics 399

Container-Managed Relationships .................................................................................. 399 Creating an EJB-QL Select Method ....................................................................... .401

UsingJDBC with EnterpriseJavaBeans ....................................................................... .428 Summary ............................................................................................................................ 435 Exercises ............................................................................................................................ 436

Chapter 11: Design Patterns and Message-Driven Beans 437

Using Design Patterns in EJB Applications ................................................................. .437 UsingJSP and Servlets with EJBs ................................................................................. .457 Developing Message-Driven Beans ............................................................................... .464

Introduction to theJava Message Service API ..................................................... .464 Introduction to the EJB Timer Service ................................................................... .465

Summary ........................................................................................................................... .4 79 Resources ......................................................................................................................... .4 79 Exercises ............................................................................................................................ 480

Chapter 12: Web Services and JAX-RPC 481

Understanding Web Services .......................................................................................... 482 Why Use Web Services? .......................................................................................... 484 The Web Services Protocol Stack ............................................................................ 485

Developing Web Services inJava .................................................................................. 487 UnderstandingJAX-RPC .......................................................................................... 488

Summary ............................................................................................................................ 508 Resources .......................................................................................................................... 509 Exercises ............................................................................................................................ 509

ix

Page 9: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Contents

Chapter 13: More J2EE Web Services Topics 511

Implementing a Session Bean As a Web Service .......................................................... 512 Implementing a Stateful Web Service ............................................................................ 525

Can Web Services Be Stateful? ................................................................................ 525 TheJAX-RPC Service Endpoint Model .................................................................. 525

Summary ............................................................................................................................ 541 Exercises ............................................................................................................................ 541

Appendix A: Installing Tomcat 543

Getting Tomcat ................................................................................................................ 543 Binary Installation to Windows ...................................................................................... 544 Binary Installation to Linux/Unix .................................................................................. 545 Source Installation ............................................................................................................ 545 Running Tomcat .............................................................................................................. 546

Appendix B: SQL and EJB-QL 547

SQL .................................................................................................................................... 547 SQL Data Types ........................................................................................................ 549 Working with Tables .................................................................................................. 551 Handling Null Values ................................................................................................ 553 Joins .............................................................................................................................. 562

EJB-QL .............................................................................................................................. 563

Appendix C: J2EE Glossary 569

Index 575

x

Page 10: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Foreword

On ce you have a good grasp of the java language and feel comfartable with applying the dass libraries using the Standard Edition of the java System Development Kit, you'll almost certainly be looking at where to go next. Progression to the Enterprise Edition of the SDK is likely to be a natural choice for many, simply because so much professional java programming effort is deployed in developing network-based applications. However, getting into developing Web Services and Enterprise Applications generally is more of a giant leap than a small step, simply because of the vast range of programming topics, technologies, and standards you have to master. This book is a very good starting point because it provides you with a structured introduction to most of what you need to know.

The previous edition of this book provided an excellent introduction to server-side programming using the java 2 Platfarm, Enterprise Edition,j2EE, and this new edition is even better, having been fully updated to cover the latest version,j2EE 1.4. In a single book package, it covers all of the key capabilities provided by thej2EE 1.4 that you are most likely to need in a real-worldjava development context. Because it starts by carefully explaining whatj2EE is all about and how it relates to the java 2 Platform, Standard Edition, you'll have an appreciation of the inter-relationships between the specific topics that you need for effective server-side programming in java from the outset. This will enable you to better see how the various technologies involved can be combined when you get into the detail.

After guiding you through the process of setting up a development environment for web applications, it continues with introductory tutorials on the co re topics in server-side programming,jSP and servlets. It doesn't end there. A whole range of supportive web programming technologies are discussed, each with working examples that show you how they can be applied. These indude jDBC for database access, EnterprisejavaBeans, XML of course, SOAP, WDSL, and many others.

The book is the product of a co operative effort by several authars who are each experts in their field. Each topic has the benefit of being explained by the author who is best equipped to provide an effective tutorial on that subject. As a professional java programmer, you need to be conversant with the latest java technologies far the development of Web applications. Y ou also need a good overall perspective on the most up-to-date version ofj2EE and what its capabilities are. This is precisely what you get in this book.

Ivor Horton, best-selling author 0/ computer programming books onJava, C, and C++

Page 11: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

About the Authors

James L. Weaver Jim Weaver is chief scientist at Learning Assistant Technologies, a company that specializes in developing learner-centric tools. He is also the President of JMentor (http://www.jmentor.com). which is aJava mentoring, training, and consulting practice.

This book is dedieated to my wife,Julie, daughters, Lori and Kelli,

and ''son, JJ Marty. Thanks Jor your eonstant love and support.

Thanks to Merrill and Barbara Bishir, Ken and Marilyn Prater,

and Walter Weaver for being such wonderful examples. Thanks

also to Laura Lee and Steve Brown, Jill Weaver, Shari and Doug

Beam, Wade and Dawn Weaver, Dan and David Wright, Jerry

and Gheryl Bishir, and Pastor Steve Golter. I appreciate Gary

Gornell, Steve Anglin, and KylieJohnston Jor the great experienee

of writing Jor Apress. Psalm 37:4

Kevin Mukhar Kevin Mukhar is a software developer from Colorado Springs, Colorado. On his most re cent project, he was on a team where the ratio of men to women was almost one to one. (Hi to Karen, Judy, Sondra,Jennifer, Vui, and Elyssa!) In the world of software development, that's like the 500-year flood, or winning the Irish Sweepstakes. For the past 5 years, he has worked on various software systems using different J2EE technologies. He has coauthored several other books, including BeginningJava Databases (ISBN 1-86100-437-0), which is one of the more popular JDBC books available today. In addition to developing software during the day, he is working on a masters degree in computer science. He recently passed the certification exam for theJava Web Component Developer Certification, and his web page is at http://home.earthlink.net/-kmukhar/.

I get a kick out of writing a program that helps someone do their job better or easier; I get a thrill when

traeking down and stamping out bugs; I think it's magie when programming turns ideas into software.

And I want to share what I know with other programmers. That's why Tm grateful to the editors at

Apress for letting me eontribute to this book. I hope that what we've written in this book will help you do

your job a little bit better or easier. Finally, I dedieate my ehapters to my wife, Anne, and my daughter.

xii

Page 12: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Jim Crume Jim Crume [email protected]) is aJava architect at Fusion Alliance, an Indianapolis-based consulting company that

specializes in web application development. Jim has spent many

years as a consultant, and specializes in architecting and

developing web-based systems, but particularly enjoysJava.

This book is dedicated to my wife, Cindy, the light of my life, who

has been more than patient with alt of my projects; my son, Chris,

and daughter, Liz, who gave up my time for this project; and my

future daughter-in-law, Michelte, who helps me laugh when it gets

stressful. Thanks can 't even come dose to expressing my

appreciation. I love you alt, and always will! Thanks to Steve

Anglin and Kyliejohnston Jor the help and guidance, and to alt

the great people at Apress for taking a chance on me. And thanks

to jim Weaver Jor trusting me enough to ask me to help. joshua

24:15

About the Authors

xiii

Page 13: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Introduction

First things first before we dive in. We, the authors, have read a lot of books on designing and developing software-some better than others-and spent a lot of time and money in the process. We had some very specific thoughts as we put this book together.

First and foremost, the focus of this book is on the practical aspects of getting started with developing distributed software for the J2EE platform. J2EE is a broad and deep subject, and getting started can be like getting a drink from a fire hose. We wanted to put together a practical approach to getting started, and spend most of our time talking about the topics that you'll use 900f0 (or more) of the time. We are serving up meat and potatoes here.

When we pick up a book on software development, we like to have the option of reading straight through, or to skip around and pick up the topics that we're interested in at a given time. As an introduction to J2EE, you'lllearn the most if you first read through each chapter in order. Later, as you go back to particular sections, you'll find it easy to skip back to refresh your memory, so feel free to skip around in this book-we hope that we've done a good job of making each topic stand on its own, and provided examples that are straightforward and relevant.

The authors of this book are software engineers first. Like you, we have more projects than time to do them in, and we understand that you don't have extra time to waste when it comes to learning new technologies. We hope the result is a book that you will pick up frequently, highlight, bookmark, and consider a valued addition to your development resources.

Like J2SE, J2EE is comprised of several packages containing classes and interfaces that define the J2EE framework. You're already familiar withJ2SE, and you got that expertise by taking theJ2SE framework one topic at a time. We'll take J2EE the same way-one topic at a time.

Page 14: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Introd uction

Who Is This Book For? This book is mainly aimed at people who already have knowledge of basic Java, and have been developing small, client-side applications for the desktop. If you have read and absorbed the information contained in an entry-level book such as Beginningjava 2 written by Ivor Horton, then you will be weH placed to begin your journey to developing server-side applications usingJ2EE.

If you are coming from another object-oriented language, such as C++ or C#, and you wish to begin developing enterprise-level applications withJava, then you will also benefit greatly from this book. The co ding concepts, principles, and constructs are similar; you just need to watch out for the syntax differences and, obviously, the different code architecture for the different technology areas of.J2EE.

What Does This Book Cover? This book will take you from having a good grip ofthe basic Java language to being able to create reusable and scaleable components ofJ2EE, such asJavaServer Pages, Enterprise.IavaBeans, and web services. At the end of the book, we will also point you in which direction to go to find out more information on your chosen areas of interest, and how you could land yourself the perfect job developing enterprise applications.

Here's a rundown of what you can expect to see as you work through the book.

Cl Chapter 1: J2EE Essentials-This chapter will layout a roadmap of what .I2EE is and how it is used as an application foundation. Y ou'll get an introduction to the primary components of .I2EE and how they fit together.

Cl Chapter 2: Getting Set-Having your machine configured correctly is essential if you want to be able to run the sampie code presented in this book. This chapter walks through the installation, configuration, and testing of the core components ofJ2EE.

Cl Chapter 3: JavaServer Pages-An introduction to the world of server-side web programming usingJSP pages. This chapter covers how to write simpleJSP pages, covering the fundamentals of the technology and how they can be very useful in your web applications.

Cl Chapter 4: Advanced JSP Topics-In this chapter, we foHow on from the basics ofJSP, and look at some deeper features of the technology, such as the expression language, custom actions, and the.ISP Standard Tag Library.

Cl Chapter 5: Servlets-Next, we cover another highly used component in.I2EE web applications­servlets, which are designed to be extensions to servers and to extend the capabilities of servers and provide dynamic behavior.

~ Chapter 6: Working with Databases-At some point in developing aJ2EE application, you will very likely need to store and manipulate data stored in a data source. This is where .IDBC comes in, and this chapter intro duces this functionality where we access the Cloudscape database.

xvi

Page 15: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Introduction

Cl Chapter 7: Advanced Topics in JDBC-After learning the basic data access functionality in the previous chapter, you will see deeper topics ofJDßC in this chapter, covering prepared state­ments and stored procedures, transactions, and locking.

Cl Chapter 8: EJß Fundamentals-In this part ofthe book, we begin to look at a feature ofJ2EE dedicated to expressing the business logic of an application-Enterprise J avaßeans orfJßs. This chapter mainly focuses on an overview of EJß technology and looks at session beans in detail.

Cl Chapter 9: EJß Entity ßeans-This second chapter on EJßs looks at another type of fJß, entity beans, and how they relate and fit in with other types of bean. We cover two different types of persistence and take a look at the EJß Query Language.

Cl Chapter 10: More EJß Topics-Creating container-managed relationships and combining the use ofJDßC and EJßs are the two topics of this chapter. We also build on the EJß-QL knowl­edge gleaned from the previous chapter by looking at EJß-QJ, select methods.

Cl Chapter 11: Design Patterns and Message-Driven Beans-In the final FJß chapter of the book, we look at what design patterns are, and how they can be applied to your EJß applications and what benefits they bring. We also cover the final type of bean-message-driven beans.

Cl Chapter 12: Web Services and JAX-RPC-The next major topic in the book covers concepts of enabling distributed applications via the magic of web services. We will look at topics such as the fundamentals, guidelines and good practices, and other issues that you should be aware of when creating web services.

Cl Chapter 13: More J2EE Web Services Topics-In the second web services chapter of this book, we move on to combining different J2EE technologies. Y ou will see how to implement a ses­sion bean as a web service, and also how to implement a stateful web service.

What You Need to Use This Book The prerequisite system and software requirements for this are very small. Since you already have a background in Java, then you will no doubt have aversion of the J2SE SDK installed on your machine already. In this book, we've used the latest version of the Standard Edition software development kit, which wasJ2SE 1.4.2. Throughout the book, we have used Microsoft Windows as our operating system but sinceJava has a "write once, run anywhere" motto, you can use another platform such as Solaris or Linux without any major changes to the code you see.

The only other piece of software you need to download and install to run the examples and follow the discussions in this book is theJ2EE 1.4 SDK. We used the final version, released in November 2003, when writing this book.

xvii

Page 16: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Introd uction

Style Conventions We have used certain layout and font styles in this book that are designed to help you to differentiate between the different kinds of information. Here are examples of the styles that are used, with an explanation of what they mean.

As you'd expect, we present code in two different ways: code used inline with text, and code that is displayed on its own. When we need to mention keywords and other coding specifics within the text (for example, in discussion relating to an if ... else construct or the beans package) we use the single-width font as shown in this sentence. If we want to show a more substantial block of code, then we display it like this:

package beans; import java.rmi . RemoteException; import javax . ejb . EJBBome; import javax . ejb . CreateException;

public interface SimpleSessionBome extends EJBBome { 11 The create() method for the SimpleSession bean public SimpleSession create()

throws CreateException, RemoteException;

Sometimes, you will see code in a mixture of gray and white backgrounds, like this:

package beans;

import java.rmi.RemoteException;

import javax . ejb . EJBObject;

public interface SimpleSession extends EJBObject { 11 The public business method on the SimpleSession bean public String getEchoString(String clientString)

throws RemoteException ;

private void Page_Load(object sender, System.EventArgs e) {

BeaderIconImageUrl - Request.ApplicationPath + "/Images/winbook .gif " ; BeaderMessage - "Informative Page";

In cases like this, we use the gray shading to draw attention to a particular section of the code-perhaps because it is new code, or it is particularly important to this part of the discussion.

Sometimes, you will need to type in commands on the command line. We will display situations like that using the following style:

xviii

> set classpath=.;%J2EE_HOME%\lib\j2ee.jar > javac -d . client/*.java

Page 17: Beginning J2EE 1.4: From Novice to Professional978-1-4302-0716-0/1.pdf · Beginning J2EE 1.4: From Novice to Professional James L. Weaver, Kevin Mukhar, andJim Crume APress Media,

Introduction

We show the prompt using a > symbol and then highlight in the bold eommands you need to type.

Advice, hints, and background information come in this type 0/ fant.

Important pieces or inrormation come in boxes like thi .

Bullets appear indented, with eaeh new bullet marked as follows:

o Important Words are in a bold type font.

Words that appear on the sereen, or in menus like File or Window, are in a similar font to the one you would see on a Windows desktop.

Keys that you press on the keyboard like Ctrl and Enter, are in italies.

How to Download the Online Code for the Book When you visit the Apress web site, http://www.apress.com/. simply Ioeate the tide through our seareh facility or by using the Online Catalog button on the left-hand side. Then you simply need to dick on Download Code on the book's detail page to obtain all the code for the book.

xix