Sei sulla pagina 1di 14

Contents

Part 1 Background
1 Why J2EE? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 The Challenges Facing IT Organizations . . . . . . . . . . . . . . . . . . 4
1.3 Requirements on Enterprise Application Development . . . . . . . . . 5
1.4 Technological Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 Why Choose Java and J2EE? . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6 A Note of Caution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7 Knowing the Technology Is not Enough . . . . . . . . . . . . . . . . . . 9
1.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Introduction to Distributed Systems . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1 What Is a Distributed Application or System? . . . . . . . . . . . . . . . 11
2.2 Why Build Distributed Programs? . . . . . . . . . . . . . . . . . . . . . . 11
2.3 How Can Java Help With Distribution? . . . . . . . . . . . . . . . . . . . 14
2.4 Distributed Object Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.5 How Can J2EE Help? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.6 Online Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 The J2EE Tour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 The J2EE Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 J2EE Technology Tour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.3.1 Communication Services . . . . . . . . . . . . . . . . . . . . . . 23
3.3.2 Horizontal Services . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3.3 Component Technologies . . . . . . . . . . . . . . . . . . . . . . 28
3.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
xiii
4 Java and Remote Method Invocation . . . . . . . . . . . . . . . . . . . . . . . . 31
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.2 Remote Method Invocation . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.2.1 The Remote Interface . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2.2 Subclassing a Server Class . . . . . . . . . . . . . . . . . . . . . 32
4.2.3 Running the rmic Compiler . . . . . . . . . . . . . . . . . . . . 36
4.2.4 Starting the Registry . . . . . . . . . . . . . . . . . . . . . . . . 36
4.3 The RMIClient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.4 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.5 Passing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.6 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5 Activate Yourself! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.2 Extending RMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.3 Implementing an Activatable Server . . . . . . . . . . . . . . . . . . . . 46
5.3.1 Remote Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.3.2 The Client Class . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.3.3 The Activatable Server . . . . . . . . . . . . . . . . . . . . . . . 48
5.3.4 The Server Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.4 Running the Activatable ClientServer . . . . . . . . . . . . . . . . . . . 51
5.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.6 Online Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
6 JNDI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.2 What You Need to Get Started . . . . . . . . . . . . . . . . . . . . . . . . 57
6.3 LDAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
6.3.1 LDAP Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
6.4 What LDAP Can Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
6.5 Using LDAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.6 Using JNDI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.7 Placing Data Into LDAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.7.1 The LDAPWrite Application . . . . . . . . . . . . . . . . . . . . 64
6.8 JNDI, RMI and LDAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7 Java Message Service (JMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.2 Message Servers and JMS . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.2.1 What Is a Message Service? . . . . . . . . . . . . . . . . . . . . 71
7.2.2 Why Use a Message Service? . . . . . . . . . . . . . . . . . . . . 72
7.2.3 What Is JMS? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7.2.4 JMS API Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.3 Point to Point Communication . . . . . . . . . . . . . . . . . . . . . . . 73
7.4 Publish and Subscribe Communication . . . . . . . . . . . . . . . . . . 74
xiv Contents
7.5 The JMS API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.5.1 Connection Factories . . . . . . . . . . . . . . . . . . . . . . . . 75
7.5.2 Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.5.3 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.5.4 Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.5.5 Destinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
7.5.6 Message Producers . . . . . . . . . . . . . . . . . . . . . . . . . 80
7.5.7 Message Consumers . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.6 Point to Point Application Development Steps . . . . . . . . . . . . . . 81
7.6.1 Publish Destinations . . . . . . . . . . . . . . . . . . . . . . . . 83
7.6.2 Define a Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.6.3 Define Clients That Receive Messages . . . . . . . . . . . . . . 88
7.6.4 Start Message Server . . . . . . . . . . . . . . . . . . . . . . . . 89
7.6.5 Compile and Start the Clients . . . . . . . . . . . . . . . . . . . 89
7.7 Publish and Subscribe Application Development Steps . . . . . . . . . 92
7.7.1 Publish the Topic . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.7.2 Define the Publisher Client . . . . . . . . . . . . . . . . . . . . . 92
7.7.3 Define the Subscriber Client . . . . . . . . . . . . . . . . . . . . 93
7.7.4 Start Message Server . . . . . . . . . . . . . . . . . . . . . . . . 94
7.7.5 Compile and Start the Clients . . . . . . . . . . . . . . . . . . . 95
7.8 Additional JMS Features . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7.8.1 Specifying Message Persistence . . . . . . . . . . . . . . . . . . 96
7.8.2 Setting the Message Priority . . . . . . . . . . . . . . . . . . . . 96
7.8.3 Defining How Long a Message Lasts . . . . . . . . . . . . . . . 96
7.8.4 Durable Subscriptions . . . . . . . . . . . . . . . . . . . . . . . 97
7.8.5 Topic Message Selectors . . . . . . . . . . . . . . . . . . . . . . 97
7.8.6 Client Authentication . . . . . . . . . . . . . . . . . . . . . . . . 97
7.8.7 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.10 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
8 Java, IDL and Object Request Brokers . . . . . . . . . . . . . . . . . . . . . . . 99
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
8.2 CORBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
8.3 Java IDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
8.3.1 Java ORB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
8.3.2 Java Name Server . . . . . . . . . . . . . . . . . . . . . . . . . . 101
8.3.3 Converting IDL to Java . . . . . . . . . . . . . . . . . . . . . . . 102
8.3.4 Implementing the Server . . . . . . . . . . . . . . . . . . . . . . 103
8.3.5 Implementing the Client . . . . . . . . . . . . . . . . . . . . . . 106
8.3.6 Compiling the Server and Client . . . . . . . . . . . . . . . . . 107
8.3.7 Running the Application . . . . . . . . . . . . . . . . . . . . . . 108
8.3.8 Java IDL and RMI . . . . . . . . . . . . . . . . . . . . . . . . . . 108
8.4 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Contents xv
9 Java Database Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
9.2 What Is JDBC? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
9.3 What the Driver Provides . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
9.4 Registering Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
9.5 Opening a Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
9.6 Obtaining Data From a Database . . . . . . . . . . . . . . . . . . . . . . 114
9.7 Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
9.8 Applets and Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
9.9 Batch updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
9.10 Scrollable and Updateable ResultSets . . . . . . . . . . . . . . . . . . . . 118
9.10.1 Scrollable ResultSets . . . . . . . . . . . . . . . . . . . . . . . . 119
9.11 Updateable ResultSets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
9.12 JDBC Data Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
9.13 Connection Pooling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
9.14 RowSet Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
9.15 JDBC Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
9.15.1 DatabaseMetaData . . . . . . . . . . . . . . . . . . . . . . . . . . 130
9.15.2 ResultSetMetaData . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9.16 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
9.17 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
10 XML and Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.2 XML Introduced . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.2.1 What is XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.2.2 What Do XML Documents Look Like? . . . . . . . . . . . . . . 136
10.2.3 XML Vocabularies . . . . . . . . . . . . . . . . . . . . . . . . . . 139
10.2.4 Working With a DTD . . . . . . . . . . . . . . . . . . . . . . . . 140
10.3 XSL Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
10.4 Processing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
10.5 The JAXP API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
10.6 The SAX API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
10.7 The DOM API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
10.8 Loading an XML Document . . . . . . . . . . . . . . . . . . . . . . . . . 156
10.9 Creating an XML Document in Java . . . . . . . . . . . . . . . . . . . . 161
10.10 Performing XSLT in JAX . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
11 JavaMail API: the Mail Is in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
11.2 The JavaMail API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
11.3 Setting up JavaMail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
11.4 Sending Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
11.5 Receiving Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
11.6 Replying to Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
11.7 Multipart MIME Messages . . . . . . . . . . . . . . . . . . . . . . . . . . 181
xvi Contents
11.8 Adding the Reply Text to a Reply . . . . . . . . . . . . . . . . . . . . . . 181
11.9 Message Forwarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.10 Sending Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.11 Sending HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.13 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Part 2 EJB Architecture
12 The EJB Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
12.2 EJB Server Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
12.3 EJB Component Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 194
12.3.1 Local and Remote Interfaces . . . . . . . . . . . . . . . . . . . . 195
12.3.2 The Process of Developing and Deploying EJB Components
in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
12.3.3 The EJB Component Classes and Interfaces . . . . . . . . . . . 197
12.4 Accessing EJBs From a Java Application Client . . . . . . . . . . . . . . 200
12.5 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
13 Stateless Session EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
13.2 Stateless Session EJB Life Cycle . . . . . . . . . . . . . . . . . . . . . . . 204
13.3 The Process of Developing a Stateless Session EJB . . . . . . . . . . . . 207
13.4 The Business Logic Interface . . . . . . . . . . . . . . . . . . . . . . . . . 208
13.5 The Life Cycle Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
13.6 The Component Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
13.6.1 The Session Context Object . . . . . . . . . . . . . . . . . . . . 211
13.6.2 Why Doesnt the Component Class Implement the
Business or Life Cycle Interfaces? . . . . . . . . . . . . . . . . . 212
13.7 The Deployment Descriptor Files . . . . . . . . . . . . . . . . . . . . . . 213
13.7.1 The ejb-jar.xml File . . . . . . . . . . . . . . . . . . . . . . . . 214
13.7.2 The JBoss jboss.xml File . . . . . . . . . . . . . . . . . . . . . 216
13.8 Deploying the EJB Component . . . . . . . . . . . . . . . . . . . . . . . 216
13.9 Accessing the EJB From a Java Application Client . . . . . . . . . . . . 217
14 Entity EJBs: How to Implement a Container-Managed Entity EJB . . . . . . . 221
14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
14.2 Entity EJB Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
14.3 The Process of Developing an Entity EJB . . . . . . . . . . . . . . . . . 227
14.4 The Business Logic Interface . . . . . . . . . . . . . . . . . . . . . . . . . 228
14.5 The Life Cycle Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
14.5.1 Creator Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
14.5.2 find Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
14.5.3 Home Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
14.5.4 Select Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Contents xvii
14.6 Primary Keys and the Primary Key Class . . . . . . . . . . . . . . . . . 233
14.7 The Component Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
14.7.1 The EntityContext Object . . . . . . . . . . . . . . . . . . . . 241
14.8 The Deployment Descriptor Files . . . . . . . . . . . . . . . . . . . . . . 241
14.8.1 The ejb-jar.xml File . . . . . . . . . . . . . . . . . . . . . . . . 242
14.8.2 The JBoss jboss.xml File . . . . . . . . . . . . . . . . . . . . . 244
14.8.3 The JBoss jbosscmp-jdbc.xml File . . . . . . . . . . . . . . . 244
14.9 The EJB Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
14.9.1 Query Language Statements . . . . . . . . . . . . . . . . . . . . 246
14.9.2 The <query> Deployment Descriptor . . . . . . . . . . . . . . 248
14.10 Accessing the EJB From a Java Application Client . . . . . . . . . . . . 249
14.11 Container-Managed Relationships . . . . . . . . . . . . . . . . . . . . . 252
14.11.1 Declaring Container-Managed Relationships in a
Component Class . . . . . . . . . . . . . . . . . . . . . . . . . . 252
14.11.2 The Relationship Deployment Descriptors . . . . . . . . . . . 256
14.11.3 The JBoss jbosscmp-jdbc.xml File . . . . . . . . . . . . . . . 258
14.12 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
15 Gluing EJBs Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
15.2 The BookStore EJB Interactions . . . . . . . . . . . . . . . . . . . . . . 261
15.3 The Environment Naming Context (ENC) . . . . . . . . . . . . . . . . . 269
15.4 Some Design Issues to Consider When Gluing EJBs Together . . . . . 273
15.4.1 Session EJBs as Faades . . . . . . . . . . . . . . . . . . . . . . . 273
15.4.2 Using JNDI From an EJB . . . . . . . . . . . . . . . . . . . . . . 275
15.4.3 When not to Use Entity EJBs . . . . . . . . . . . . . . . . . . . . 275
15.4.4 Compile-Time Checking of the Implementation Classs
Conformance to its Business Logic Interface . . . . . . . . . . 277
15.4.5 Improving Performance Through the Use of Bulk
Accessor/Updator Methods . . . . . . . . . . . . . . . . . . . . 278
15.5 The Cart EJB Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
15.6 The Timer Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
16 Message-Driven EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
16.2 Message-Driven EJB Life Cycle . . . . . . . . . . . . . . . . . . . . . . . 291
16.3 The Component Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
16.4 The Deployment Descriptor Files . . . . . . . . . . . . . . . . . . . . . . 297
16.4.1 The ejb-jar.xml File . . . . . . . . . . . . . . . . . . . . . . . . 297
16.4.2 The ejb-jar.xml file (for EJB 2.1) . . . . . . . . . . . . . . . . 299
16.4.3 The JBoss jboss.xml File . . . . . . . . . . . . . . . . . . . . . 301
16.4.4 The JBoss jboss-destinations-service.xml file . . . . . . 302
16.4.5 DebugMonitor Connected to a JMS Topic . . . . . . . . . . . . 302
16.5 Accessing the EJB From Other EJBs . . . . . . . . . . . . . . . . . . . . . 307
xviii Contents
Part 3 Servlets and JSPs
17 Web Applications in Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
17.2 What Are Servlets? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
17.3 Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
17.4 Structure of a Web Application . . . . . . . . . . . . . . . . . . . . . . . 322
17.5 How Servlets Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
17.6 Why Use Servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
17.7 The Structure of the Servlet API . . . . . . . . . . . . . . . . . . . . . . 325
17.8 Steps for Developing and Deploying a Web Application . . . . . . . . . 326
17.9 Starting Tomcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
17.10 A Second Example Servlet . . . . . . . . . . . . . . . . . . . . . . . . . . 332
17.11 Should You Use doGet or doPost? . . . . . . . . . . . . . . . . . . . . . . 337
17.12 Tomcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
17.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
17.14 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
17.15 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
18 Session Management and Life Cycle Monitoring . . . . . . . . . . . . . . . . . . 341
18.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
18.2 Session Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
18.3 Session Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.3.1 URL Rewriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
18.3.2 Hidden Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
18.3.3 Secure Sockets Layer Sessions . . . . . . . . . . . . . . . . . . . 345
18.3.4 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
18.3.5 Choosing a Session Tracking Approach . . . . . . . . . . . . . 346
18.4 A Session Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
18.5 More Session Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
18.6 Session State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
18.7 Session Life Cycle Monitoring . . . . . . . . . . . . . . . . . . . . . . . . 354
18.8 Servlet Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
18.9 ServletContext Example . . . . . . . . . . . . . . . . . . . . . . . . . . 358
18.10 Servlet Life Cycle Events . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
18.11 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
19 Java Server Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
19.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
19.2 What Is a JSP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
19.3 A Very Simple JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
19.4 The Components of a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
19.4.1 Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
19.4.2 Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
19.4.3 Implicit Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
19.4.4 JSP Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Contents xix
19.5 Making JSPs Interactive . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
19.6 Why Use JSPs? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
19.7 Problems With JSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
20 JSP Tags and Implicit Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
20.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
20.2 JSP Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
20.2.1 JSP Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
20.2.2 Scripting Elements . . . . . . . . . . . . . . . . . . . . . . . . . 380
20.2.3 Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
20.3 Implicit Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
20.4 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
21 JSP Tag Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
21.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
21.2 Why Use Tag Libraries? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
21.3 Key Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
21.4 Building a Custom Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
21.5 The Tag Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
21.5.1 Other Tag Interfaces and Classes . . . . . . . . . . . . . . . . . 393
21.6 Creating a Tag Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
21.6.1 Implement the Tag Handler Class . . . . . . . . . . . . . . . . . 394
21.6.2 Define the Tag Library Descriptor . . . . . . . . . . . . . . . . 395
21.6.3 Map the Tag Library . . . . . . . . . . . . . . . . . . . . . . . . . 396
21.6.4 Import the Tag Library . . . . . . . . . . . . . . . . . . . . . . . 397
21.6.5 Run the Web Application . . . . . . . . . . . . . . . . . . . . . . 398
21.7 Adding Attributes to a Tag . . . . . . . . . . . . . . . . . . . . . . . . . . 398
21.8 Including Body Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
21.9 Guidelines for Developing Tag Libraries . . . . . . . . . . . . . . . . . . 406
21.10 Introducing Scripting Variables . . . . . . . . . . . . . . . . . . . . . . . 407
21.11 Nested Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
21.12 Tag Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
21.13 Handling Tag Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
21.14 JSTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
21.15 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
21.16 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
22 Request Dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
22.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
22.2 Servlet Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
22.3 Request Dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
22.3.1 The RequestDispatcher Interface . . . . . . . . . . . . . . . . 418
22.4 Obtaining a RequestDispatcher . . . . . . . . . . . . . . . . . . . . . . 418
22.4.1 Forwarding Requests . . . . . . . . . . . . . . . . . . . . . . . . 420
22.4.2 An Example of Forwarding . . . . . . . . . . . . . . . . . . . . . 420
22.4.3 Including Via Request Dispatching . . . . . . . . . . . . . . . . 424
xx Contents
23 Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
23.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
23.2 Filters the Very Concept! . . . . . . . . . . . . . . . . . . . . . . . . . . 431
23.3 What Can a Filter Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
23.4 The Filter API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
23.5 Implementing a Simple Filter . . . . . . . . . . . . . . . . . . . . . . . . 435
23.6 The Logging Filter Example . . . . . . . . . . . . . . . . . . . . . . . . . 439
23.7 Wrapping Request and Response Objects . . . . . . . . . . . . . . . . . 443
23.8 Filtering XML to Generate HTML . . . . . . . . . . . . . . . . . . . . . . 443
24 Securing Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
24.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
24.2 Traditional Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
24.2.1 Use the Web Server . . . . . . . . . . . . . . . . . . . . . . . . . 453
24.2.2 Do-It-Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
24.3 Container-Managed Security . . . . . . . . . . . . . . . . . . . . . . . . 455
24.3.1 Defining Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
24.3.2 Configuring Access to Web Resources . . . . . . . . . . . . . . 458
24.3.3 Four Types of Authentication . . . . . . . . . . . . . . . . . . . 460
24.4 Programmatic Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
24.5 JSP Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
24.5.1 Enabling and Disabling EL Evaluation . . . . . . . . . . . . . . 467
24.5.2 Enabling and Disabling Scripting . . . . . . . . . . . . . . . . . 467
24.5.3 Declaring Page Encodings . . . . . . . . . . . . . . . . . . . . . 467
24.5.4 Defining Implicit Includes . . . . . . . . . . . . . . . . . . . . . 468
24.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
24.7 Online Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
25 Deployment Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
25.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
25.2 Context Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
25.3 Servlet Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
25.4 Servlet Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
25.5 Session Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
25.6 Welcome Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
25.7 Error Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
25.8 MIME Mappings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
25.9 Distributable Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 478
25.10 Deployment Descriptor in J2EE 1.3 . . . . . . . . . . . . . . . . . . . . . 479
25.11 Deploying J2EE Applications in J2SE 1.4 . . . . . . . . . . . . . . . . . . 480
26 Accessing EJBs from Servlets/JSPs . . . . . . . . . . . . . . . . . . . . . . . . . 483
26.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
26.2 Client Access to EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
26.3 Accessing EJBs From a Web Application . . . . . . . . . . . . . . . . . . 484
26.3.1 The Web Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Contents xxi
26.3.2 The Enterprise Archive . . . . . . . . . . . . . . . . . . . . . . . 486
26.4 Caching EJB References . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
26.5 An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
26.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Part 4 Additional Technologies
27 Deployment Issues: Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . 497
27.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
27.2 Transaction Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
27.3 Types of Transaction Supported by EJB Servers . . . . . . . . . . . . . 501
27.4 Container-Managed Transactions . . . . . . . . . . . . . . . . . . . . . . 501
27.4.1 The Required Attribute . . . . . . . . . . . . . . . . . . . . . . 502
27.4.2 The NotSupported Attribute . . . . . . . . . . . . . . . . . . . 502
27.4.3 The Supports Attribute . . . . . . . . . . . . . . . . . . . . . . 503
27.4.4 The RequiresNew Attribute . . . . . . . . . . . . . . . . . . . . 503
27.4.5 The Mandatory Attribute . . . . . . . . . . . . . . . . . . . . . . 503
27.4.6 The Never Attribute . . . . . . . . . . . . . . . . . . . . . . . . . 505
27.4.7 Transaction Deployment Descriptors . . . . . . . . . . . . . . 505
27.5 Bean-Managed Transactions . . . . . . . . . . . . . . . . . . . . . . . . . 507
27.5.1 The UserTransaction Interface . . . . . . . . . . . . . . . . . 507
27.5.2 Obtaining and using a UserTransaction object . . . . . . . . 509
27.6 Transaction Isolation Levels . . . . . . . . . . . . . . . . . . . . . . . . . 510
27.6.1 Lock Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
27.6.2 Specifying Isolation Levels . . . . . . . . . . . . . . . . . . . . . 514
27.7 Transactions and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . 515
27.8 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
28 Deployment Issues: Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
28.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
28.2 Security Concepts and Architecture . . . . . . . . . . . . . . . . . . . . 518
28.2.1 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
28.2.2 Access Control (Authorization) . . . . . . . . . . . . . . . . . . 520
28.3 EJB Container-Managed Security . . . . . . . . . . . . . . . . . . . . . . 521
28.3.1 Declarative Security . . . . . . . . . . . . . . . . . . . . . . . . . 521
28.3.2 Programmatic Security . . . . . . . . . . . . . . . . . . . . . . . 525
28.3.3 Stakeholder Responsibilities . . . . . . . . . . . . . . . . . . . . 526
28.4 Example Use of the Java Authentication and Authorization
Service (JAAS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
28.5 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
29 Bean-Managed Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
29.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
29.2 The Entity EJB Life Cycle Revisited . . . . . . . . . . . . . . . . . . . . . 533
29.3 BookItem EJB: the BMP version . . . . . . . . . . . . . . . . . . . . . . . 535
29.4 The Deployment Descriptor Files . . . . . . . . . . . . . . . . . . . . . . 546
29.5 Accessing the BookItem BMP Entity From a Client . . . . . . . . . . . 548
xxii Contents
30 Stateful Session EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
30.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
30.2 Stateful Session EJB Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . 550
30.3 Rules on Allowable Instance Variables in the Implementation
Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
30.4 The Process of Developing a Stateful Session EJB . . . . . . . . . . . . 552
30.4.1 The Purchase EJB Business Logic Interface . . . . . . . . . . . 552
30.4.2 The Purchase EJB Life Cycle Interface . . . . . . . . . . . . . . 553
30.4.3 The Purchase EJB Component class . . . . . . . . . . . . . . . 554
30.5 Transaction Synchronization Using the SessionSynchronization
Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559
30.6 The Deployment Descriptor Files . . . . . . . . . . . . . . . . . . . . . . 560
31 J2EE Connector Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
31.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
31.2 Architectural Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
31.3 Connection Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
31.4 Transaction Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
31.5 Security Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
31.6 Common Client Interface (CCI) . . . . . . . . . . . . . . . . . . . . . . . 570
31.7 Deploying Resource Adapters . . . . . . . . . . . . . . . . . . . . . . . . 575
31.8 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
32 From Java to SVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
32.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
32.2 What is SVG? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
32.2.1 Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
32.2.2 Disadvantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
32.2.3 Obtaining an SVG Viewer . . . . . . . . . . . . . . . . . . . . . 578
32.2.4 What Does SVG Look Like? . . . . . . . . . . . . . . . . . . . . 579
32.3 Creating SVG Using Java . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
32.3.1 Using the DOM API . . . . . . . . . . . . . . . . . . . . . . . . . 580
32.3.2 Converting XML to SVG . . . . . . . . . . . . . . . . . . . . . . 581
32.4 Using Batik . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
32.4.1 SVG Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
32.4.2 SVG Rasterizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
32.4.3 SVG Generator: Generating SVG Content from
Java Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
32.4.4 SwingDraw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
32.5 Servlets and JSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
32.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
32.7 Online References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
32.8 Appendix: SVGCreator.java . . . . . . . . . . . . . . . . . . . . . . . . 591
33 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
33.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Contents xxiii
33.2 What Are Web Services? . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
33.2.1 What Is SOAP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
33.2.2 SOAP With Attachments . . . . . . . . . . . . . . . . . . . . . . 595
33.2.3 What Is WSDL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
33.2.4 What Is UDDI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
33.3 What Is Axis? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
33.4 An Axis-Based Web Services Client . . . . . . . . . . . . . . . . . . . . . 599
33.5 Creating a Simple Web Service Driver . . . . . . . . . . . . . . . . . . . 602
33.5.1 Setting up Tomcat for Web Services . . . . . . . . . . . . . . . 602
33.5.2 Creating a Very Simple Web Service . . . . . . . . . . . . . . . 603
33.5.3 Configuring a Web Service . . . . . . . . . . . . . . . . . . . . . 605
33.5.4 Where Is WSDL? . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
33.6 Java Web Services Development Pack . . . . . . . . . . . . . . . . . . . . 610
33.7 SOAP with Attachments API for Java . . . . . . . . . . . . . . . . . . . . 612
33.8 Web Services and J2EE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
33.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
33.10 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
Part 5 Design
34 J2EE Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
34.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
34.2 The Motivation Behind Patterns . . . . . . . . . . . . . . . . . . . . . . . 620
34.3 Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
34.3.1 What Are Design Patterns? . . . . . . . . . . . . . . . . . . . . . 621
34.3.2 What They Are Not . . . . . . . . . . . . . . . . . . . . . . . . . 621
34.3.3 Architectural Patterns . . . . . . . . . . . . . . . . . . . . . . . . 622
34.3.4 Documenting Patterns . . . . . . . . . . . . . . . . . . . . . . . 622
34.3.5 When to Use Patterns . . . . . . . . . . . . . . . . . . . . . . . . 623
34.3.6 Strengths and Limitations of Design Patterns . . . . . . . . . 623
34.4 What Are J2EE Design Patterns? . . . . . . . . . . . . . . . . . . . . . . . 624
34.5 A Catalog of J2EE Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . 625
34.6 The FrontController Pattern . . . . . . . . . . . . . . . . . . . . . . . . . 626
34.6.1 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
34.6.2 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
34.6.3 Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
34.6.4 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
34.6.5 Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
34.6.6 Consequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
34.6.7 Related Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
34.7 The RequestEventDispatcher Pattern . . . . . . . . . . . . . . . . . . 629
34.7.1 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
34.7.2 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
34.7.3 Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
34.7.4 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
34.7.5 Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
xxiv Contents
34.7.6 Consequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
34.7.7 Related Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
34.8 J2EE-based ModelViewController . . . . . . . . . . . . . . . . . . . . 634
34.8.1 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
34.8.2 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
34.8.3 Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
34.8.4 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
34.8.5 Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
34.8.6 Consequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
34.8.7 Related Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
34.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
34.10 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
34.11 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
35 The Fault Tracker J2EE Case Study . . . . . . . . . . . . . . . . . . . . . . . . . 641
35.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
35.2 The Fault Tracker Application . . . . . . . . . . . . . . . . . . . . . . . . 641
35.2.1 Requests for Change . . . . . . . . . . . . . . . . . . . . . . . . . 642
35.2.2 Problem Reporting . . . . . . . . . . . . . . . . . . . . . . . . . 643
35.3 Using the Fault Tracker . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
35.4 The Design of the Fault Tracker . . . . . . . . . . . . . . . . . . . . . . . 649
35.4.1 What Is the Architecture? . . . . . . . . . . . . . . . . . . . . . 649
35.5 Summary and Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . 656
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Contents xxv
http://www.springer.com/978-1-85233-704-9

Potrebbero piacerti anche