SlideShare a Scribd company logo
Table of Contents
Introduction..............................................................................................…….xxix
Chapter 1: Getting Started with Web Applications in Java ...............................1
Introduction to Web Applications............................................................................................................................2
Benefits of Web Applications....................................................................................................................................5
Technologies used in Web Applications..................................................................................................................5
Describing JDBC................................................................................................................................................ 5
Exploring the JDBC Architecture........................................................................................................... 6 
Describing Java Servlets................................................................................................................................... 7
Advantages of Java Servlets................................................................................................................... 8 
Describing JSP.................................................................................................................................................... 8
Request Processing of a JSP Page .......................................................................................................... 9
Describing the JSP Life-cycle.................................................................................................................. 9 
Introduction to Web Architecture Models ............................................................................................................10
Describing the Model-1 Architecture ........................................................................................................... 10
Limitations of the Model-1 Architecture ............................................................................................ 11 
Describing the Model-2 Architecture ........................................................................................................... 11
Advantages of the Model-2 Architecture ........................................................................................... 12 
Introduction to the MVC Architecture...................................................................................................................12
Describing the Model Component................................................................................................................ 13
Describing the View Component.................................................................................................................. 13
Describing the Controller Component ......................................................................................................... 13
Summary....................................................................................................................................................................14
Exercise ......................................................................................................................................................................14
Chapter 2: Getting Started with JDBC ..............................................................15
Introducing ODBC....................................................................................................................................................16
Defining ODBC.........................................................................................................................................................16
Listing Features of ODBC .............................................................................................................................. 17
Table of Contents
vi
Describing the ODBC Components .............................................................................................................. 17
The Application Component................................................................................................................ 18 
The DriverManager Component ......................................................................................................... 18 
The Driver Component......................................................................................................................... 18 
The Datasource Component................................................................................................................. 19 
Describing the ODBC Architecture............................................................................................................... 19
The Single-tier ODBC Architecture..................................................................................................... 19 
The Multiple-tier ODBC Architecture................................................................................................. 20 
Introducing JDBC .....................................................................................................................................................20
Describing Components of JDBC.................................................................................................................. 22
Listing Features of JDBC ................................................................................................................................ 22
Listing New Features in JDBC 4.0................................................................................................................. 24
Exploring the JDBC Architecture............................................................................................................................25
The Type-1 Driver........................................................................................................................................... 26
Advantages of the Type-1 Driver ........................................................................................................ 27 
Disadvantages of the Type-1 Driver ................................................................................................... 27 
Situations to Use the Type-1 Driver .................................................................................................... 27 
The Type-2 Driver (Java to native API)........................................................................................................ 27
Advantages of the Type-2 Driver ........................................................................................................ 28 
Disadvantages of the Type-2 Driver ................................................................................................... 28 
Examples of the Type-2 Driver ............................................................................................................ 28 
Situations to Use the Type-2 Driver .................................................................................................... 28 
The Type-3 Driver (Java to Network Protocol/All Java Driver)............................................................... 29
Advantages of the Type-3 Driver ........................................................................................................ 29 
Disadvantages of the Type-3 Driver ................................................................................................... 29 
Examples of the Type-3 Driver ............................................................................................................ 29 
Situations to Use the Type-3 Driver .................................................................................................... 30 
The Type-4 Driver (Java to Database protocol)........................................................................................... 30
Advantages of the Type-4 Driver ........................................................................................................ 30 
Disadvantage of the Type-4 Driver ..................................................................................................... 30 
Examples of the Type-4 Driver ............................................................................................................ 31 
Summary....................................................................................................................................................................31
Exercise ......................................................................................................................................................................32
State True or False ....................................................................................................................................................32 
Chapter 3: Working with JDBC APIs.................................................................33
Introducing JDBC API..............................................................................................................................................34
Explaining the Types of JDBC APIs.............................................................................................................. 35 
The JDBC Core API ............................................................................................................................... 35 
The JDBC Extension API....................................................................................................................... 36 
Table of Contents
vii
Listing the New APIs Added to JDBC 4.0.................................................................................................... 37 
Describing the Major Classes and Interfaces............................................................................................... 38 
The DriverManager Class..................................................................................................................... 38 
The Driver Interface .............................................................................................................................. 39 
The Connection Interface...................................................................................................................... 40 
The Statement Interface ........................................................................................................................ 42 
Communicating with Databases by using JDBC APIs.........................................................................................45
Step 1: Obtaining a Connection..................................................................................................................... 46 
Obtaining an Connection using Driver object.................................................................................... 46 
Step 1.i: Registering a Driver object with DriverManager................................................................ 47 
Step 1.ii: Establishing a Connection using DriverManager.............................................................. 48 
Step 2: Creating a JDBC Statement Object ................................................................................................... 49 
Step 3: Executing SQL Statements................................................................................................................. 49 
Step 4: Closing the Connection...................................................................................................................... 49 
Creating a Simple Application................................................................................................................................50
Configuring the Application.......................................................................................................................... 51 
Creating a Table..................................................................................................................................... 51 
Creating a DSN................................................................................................................................................ 51 
Understanding Various JDBC Drivers...................................................................................................................53
The OCI8 Driver for Oracle............................................................................................................................ 54 
The IDS Driver................................................................................................................................................. 54 
Installing the IDS Server ....................................................................................................................... 54 
Configuring IDS Driver ........................................................................................................................ 57 
The Thin driver for Oracle ............................................................................................................................. 57 
Summary....................................................................................................................................................................58
Exercise ......................................................................................................................................................................58
Fill in the blanks with appropriate words or phrases:.........................................................................................58
Chapter 4: Implementing JDBC Statements and ResultSets ..........................59
Describing JDBC Statement.....................................................................................................................................60
Working with the Statement Interface...................................................................................................................60
Exploring the Methods of Statement ............................................................................................................ 60 
The executeUpdate (String sqlStatement) Method............................................................................ 61 
The executeQuery (String query) Method.......................................................................................... 61 
The execute (String sqlStatement) Method......................................................................................... 61 
The getResultSet () Method .................................................................................................................. 62 
The getUpdateCount () Method .......................................................................................................... 62 
Using Statement .............................................................................................................................................. 62 
Creating a Table..................................................................................................................................... 62 
Inserting a Row...................................................................................................................................... 64 
Table of Contents
viii
Working with the PreparedStatement Interface...................................................................................................65
Comparing Statement and PreparedStatement Objects............................................................................. 66 
Describing the setXXX methods of PreparedStatement............................................................................. 67 
Listing the Advantages and Disadvantages of PreparedStatement ......................................................... 69 
Using PreparedStatement .............................................................................................................................. 69 
Creating a PreparedStatement Object................................................................................................. 69 
Setting the Values for Parameters........................................................................................................ 70 
Executing the PreparedStatement ....................................................................................................... 70 
Using PreparedStatement with Parameters................................................................................................. 70 
Exploring the Usage of the PreparedStatement Object .............................................................................. 73 
Working with the CallableStatement Interface.....................................................................................................73
Describing Stored Procedures ....................................................................................................................... 73 
Listing the Benefits of Working with a Stored Procedure ......................................................................... 74 
Using CallableStatement ................................................................................................................................ 74 
Creating the CallableStatement object ................................................................................................ 74 
Setting the Values of the Parameters................................................................................................... 75 
Registering the OUT Parameter Type................................................................................................. 75 
Executing the Stored Procedure or Function ..................................................................................... 75 
Retrieving the Parameter Values ......................................................................................................... 75 
Using CallableStatement with Parameters .................................................................................................. 75 
Executing a Stored Procedure with IN Parameters........................................................................... 75 
Executing a Stored Procedure with OUT Parameters....................................................................... 77 
Calling Functions by Using CallableStatement........................................................................................... 79 
Using Cursors in CallableStatement............................................................................................................. 81 
Comparing Procedure and Function ............................................................................................................ 82 
Working with the ResultSet Interface ....................................................................................................................82
Describing the Methods of ResultSet............................................................................................................ 83 
Using ResultSet................................................................................................................................................ 85 
Moving the Cursor Position ................................................................................................................. 86 
Reading the Column Values................................................................................................................. 86 
Retrieving All the Rows from a Table .......................................................................................................... 89 
Retrieving a Particular Column Using ResultSet........................................................................................ 91 
Handling NULL Values...........................................................................................................................................94
Working with the ResultSetMetaData Interface...................................................................................................95
Describing ResultSetMetaData...................................................................................................................... 95 
Using ResultSetMetaData .............................................................................................................................. 96 
Creating SQLEditor in Java.....................................................................................................................................98
Creating the Command-Based SQLEditor................................................................................................... 98 
Creating the Windows-Based SQLEditor................................................................................................... 100 
Table of Contents
ix
Using Advanced Concepts of ResultSet ..............................................................................................................104
Exploring Characteristics of the ResultSet Object..................................................................................... 104 
ResultSet Types.................................................................................................................................... 104 
ResultSet Concurrency........................................................................................................................ 105 
ResultSet Holdability .......................................................................................................................... 106 
Setting the ResultSet Type and ResultSet Concurrency........................................................................... 106 
Using ResultSet Objects to Manipulate Data............................................................................................. 112 
Using the ResultSet Object to Update Data...................................................................................... 112 
Using the ResultSet Object to Delete a Row..................................................................................... 114 
Using a ResultSet Object to Insert a Row.......................................................................................... 116 
Closing the Connection..........................................................................................................................................118
Closing the Statement and ResultSet.......................................................................................................... 118 
Working with the DatabaseMetaData Interface .................................................................................................119
Retrieving Database and Driver Details..................................................................................................... 121 
Retrieving Table Description....................................................................................................................... 122 
Retrieving Column Details........................................................................................................................... 124 
Retrieving Data from a Microsoft Excel Sheet........................................................................................... 125 
Summary..................................................................................................................................................................128
Exercise ....................................................................................................................................................................129
Chapter 5: Describing Advanced JDBC Concepts.........................................131
Exploring the SQL 99 Data Types.........................................................................................................................132
The BLOB Data Type .................................................................................................................................... 132 
Storing BLOB Values........................................................................................................................... 133 
Reading BLOB Values......................................................................................................................... 135 
The CLOB Data Type.................................................................................................................................... 136 
Storing CLOB Values .......................................................................................................................... 137 
Reading CLOB Values......................................................................................................................... 138 
The Struct (Object) Data Type ..................................................................................................................... 140 
Using User-Defined Object Types in Java to Represent Database Object Types......................... 140 
Creating a JDBC UDT.......................................................................................................................... 141 
Mapping the JDBC UDT..................................................................................................................... 141 
Implementing UDT ............................................................................................................................. 141 
Using the java.sql.Struct Interface ..................................................................................................... 145 
The Array Data Type .................................................................................................................................... 146 
The Ref Data Type......................................................................................................................................... 151 
Working with the ROWID Type...........................................................................................................................151
Working with Batch Updates................................................................................................................................152
Using Batch Updates with the Statement Object ...................................................................................... 153 
The Batch Update Methods................................................................................................................ 153 
Table of Contents
x
The BatchUpdateException Exception.............................................................................................. 154 
Using Batch Updates with the PreparedStatement Object ...................................................................... 156 
Describing SQL/XML and XML support............................................................................................................157
Retrieving Auto Generated Keys..........................................................................................................................158
Working with RowSets in JDBC ...........................................................................................................................161
The Connected RowSets............................................................................................................................... 161 
The Disconnected RowSets.......................................................................................................................... 161 
Using the RowSet at Design Time............................................................................................................... 162 
Setting the Properties of the RowSet Instance ................................................................................. 162 
Working with RowSet Events ............................................................................................................ 162 
Using RowSets at Run Time ........................................................................................................................ 162 
Setting Parameter Values of a RowSet Object.................................................................................. 163 
Executing RowSets .............................................................................................................................. 163 
Traversing a RowSet............................................................................................................................ 163 
Exploring Connection Pooling..............................................................................................................................163
Working with Connection Pool ............................................................................................................................165
Working with Transactions...................................................................................................................................166
Describing ACID Properties ........................................................................................................................ 166 
Atomicity .............................................................................................................................................. 167 
Consistency........................................................................................................................................... 167 
Isolation................................................................................................................................................. 167 
Durability.............................................................................................................................................. 167 
Types of Transactions................................................................................................................................... 167 
Performing Transaction Management........................................................................................................ 168 
Describing the Wrapper Interface ........................................................................................................................171
The isWrapperFor() Method........................................................................................................................ 171 
The unwrap() Method .................................................................................................................................. 171 
Describing SQLException......................................................................................................................................171
Summary..................................................................................................................................................................173
Exercise ....................................................................................................................................................................174
Chapter 6: Understanding Java Servlet ..........................................................175
Understanding the Need for Server-Side Extensions ........................................................................................176
Introducing CGI......................................................................................................................................................176
Introducing Java Servlet ........................................................................................................................................178
Advantages of a Servlet................................................................................................................................ 178 
New Features of Servlet 2.5.......................................................................................................................... 178 
Exploring the Servlet Container ...........................................................................................................................180
Describing the Request Processing Mechanism........................................................................................ 180 
Describing the Types of Servlet Container Configurations..................................................................... 180 
Table of Contents
xi
The Standalone Container .................................................................................................................. 181 
The In-Process Container.................................................................................................................... 181 
The Out-Process Containers............................................................................................................... 182 
Introducing the Servlet API...................................................................................................................................182
Describing the javax.servlet Package.......................................................................................................... 183 
Describing the javax.servlet.http Package.................................................................................................. 184 
Implementing a Servlet Object..............................................................................................................................185
The javax.servlet.Servlet Interface............................................................................................................... 185 
The javax.servlet.ServletConfig Interface<H2>......................................................................................... 185 
Understanding the Servlet LifeCycle ...................................................................................................................186
Describing the Stages of the Servlet LifeCycle .......................................................................................... 186 
Loading a Servlet ................................................................................................................................. 186 
Initializing a Servlet............................................................................................................................. 187 
Handling Request................................................................................................................................ 187 
Destroying a Servlet (End of service)................................................................................................ 189 
Exploring the Servlet Life Cycle Methods ................................................................................................. 189 
The init () method ................................................................................................................................ 189 
The service( ) Method.......................................................................................................................... 189 
The destroy () Method......................................................................................................................... 190 
Developing the First Servlet Application ............................................................................................................190
Creating the home.html Page ...................................................................................................................... 190 
Creating the LifeCycleServlet...................................................................................................................... 191 
Creating the Deployment Descriptor ......................................................................................................... 191 
Deploying Web Application........................................................................................................................ 192 
Running the LifeCycle Application ............................................................................................................ 193 
Understanding the Request Processing Workflow ............................................................................................194
Request Navigation....................................................................................................................................... 195 
Request Delegation ....................................................................................................................................... 196 
Working with the GenericServlet Class...............................................................................................................197
Exploring Methods of the GenericServlet Class ...................................................................................... 198 
Using the GenericServlet Class .................................................................................................................. 199 
Creating the Home.html Page............................................................................................................ 199 
Developing the HelloServlet.java Servlet......................................................................................... 200 
Deploying and Running the Application ......................................................................................... 200 
Summary..................................................................................................................................................................201
Exercise ....................................................................................................................................................................202
Chapter 7: Understanding Request Processing and HTTP...........................203
Implementing the ServletRequest Interface........................................................................................................204
Managing the Servlet Object as a Throwaway Object.............................................................................. 204 
Table of Contents
xii
Managing the ServletRequest Object Pool................................................................................................. 204 
Working with Request Parameters............................................................................................................. 205 
Creating the Login Form..................................................................................................................... 206 
Creating the LoginServlet Servlet...................................................................................................... 206 
Creating the Deployment Descriptor File......................................................................................... 208 
Running the Application .................................................................................................................... 209 
Working with Initialization Parameters ..............................................................................................................210
Exploring the Need for Initialization Parameters..................................................................................... 211 
Retrieving Initialization Parameters........................................................................................................... 211 
Handling Servlet Initialization Parameters ............................................................................................... 212 
Creating the Home.html File.............................................................................................................. 212 
Creating the InitParamsServlet Servlet............................................................................................. 212 
Creating the Deployment Descriptor File......................................................................................... 213 
Running the Application .................................................................................................................... 214 
Working with Context Initialization Parameters................................................................................................216
Retrieving Context Initialization Parameters ............................................................................................ 216 
Using Context Initialization Parameters .................................................................................................... 216 
Creating the Home.html File.............................................................................................................. 217 
Creating the Login.html File .............................................................................................................. 217 
Creating the Register.html File .......................................................................................................... 218 
Creating the RegistrationServlet Servlet........................................................................................... 219 
Creating the LoginServlet Servlet...................................................................................................... 221 
Creating the Deployment Descriptor File......................................................................................... 223 
Running the Application .................................................................................................................... 225 
Understanding ServletResponse...........................................................................................................................227
Understanding Request Dispatching...................................................................................................................228
Navigation...................................................................................................................................................... 229 
Delegation ...................................................................................................................................................... 230 
Dispatching the Request........................................................................................................................................230
Getting a RequestDispatcher object............................................................................................................ 230 
The getRequestDispatcher() Method of ServletContext ................................................................. 230 
The getNamedDispatcher() Method of ServletContext .................................................................. 231 
The getRequestDispatcher() Method of ServletRequest................................................................. 231 
Comparing the getRequestDispatcher() Methods of ServletContext and ServletRequest......... 231 
Comparing the getRequestDispatcher() & getNamedDispatcher() Methods.............................. 232 
Understanding the include() and forward() Methods of RequestDispatcher ....................................... 232 
Describing the include() Method....................................................................................................... 232 
Describing the forward() Method...................................................................................................... 234 
Comparing the include() and forward() Methods........................................................................... 235 
Table of Contents
xiii
Considering the Situations to use the include() and forward() Methods..................................... 236 
Working with RequestDispatcher............................................................................................................... 236 
Creating the Home.html File.............................................................................................................. 236 
Creating the TestServlet1 Servlet....................................................................................................... 237 
Creating the TestServlet2 Servlet....................................................................................................... 238 
Creating the Deployment Descriptor File......................................................................................... 239 
Running the Application .................................................................................................................... 240 
Describing Request Attributes..............................................................................................................................242
Working with Request Attributes............................................................................................................... 242 
Creating the Home.html File.............................................................................................................. 243 
Creating the ValidationServlet Servlet.............................................................................................. 243 
Creating the AddServlet Servlet ........................................................................................................ 244 
Creating the SubServlet Servlet ......................................................................................................... 244 
Creating the ResponseServlet Servlet ............................................................................................... 245 
Creating the Deployment Descriptor File......................................................................................... 246 
Running the Application .................................................................................................................... 247 
Describing HTTP Basic ..........................................................................................................................................249
Describing HTTP Status Codes ................................................................................................................... 249 
1XX – Informational ............................................................................................................................ 249 
2XX – Success ....................................................................................................................................... 249 
3XX – Redirection ................................................................................................................................ 249 
4XX – Client Error................................................................................................................................ 250 
5XX – Server Error ............................................................................................................................... 250 
Describing the HttpServletRequest & HttpServletResponse Interfaces ..........................................................250
Working with HttpServletRequest ............................................................................................................. 251 
Working with HttpServletResponse........................................................................................................... 251 
Exploring the Methods for Response Headers ................................................................................ 252 
Exploring the Methods for Buffering................................................................................................ 253 
Comparing RequestDispatcher forward and sendRedirect........................................................... 253 
Handling the HttpServletRequest and HttpServletResponse Interfaces ............................................... 254 
Creating the Home.html File.............................................................................................................. 254 
Creating the HttpServletRequestEx Servlet ..................................................................................... 254 
Creating the Deployment Descriptor File......................................................................................... 255 
Running the Application .................................................................................................................... 256 
Describing HttpServlet...........................................................................................................................................258
The HttpServlet Lifecycle............................................................................................................................. 259 
Summary..................................................................................................................................................................259
Exercise ....................................................................................................................................................................260
Table of Contents
xiv
Chapter 8: Handling Sessions in Servlet ........................................................261
Introducing Session Tracking ...............................................................................................................................262
Describing URL Rewriting ....................................................................................................................................263
Using Query String for URL Rewriting...................................................................................................... 263 
Using Path Info for URL Rewriting ............................................................................................................ 263 
Listing the Disadvantages of URL Rewriting............................................................................................ 264 
Considering Situations to use URL Rewriting .......................................................................................... 264 
Exploring Hidden Form Field...............................................................................................................................264
Listing the Advantages and Disadvantages of Hidden Form Field ....................................................... 265 
Considering the Situations to use Hidden Form Fields ........................................................................... 265 
Working with URL Rewriting and Hidden Form Field ....................................................................................265
Creating the SiteHome.html Page............................................................................................................... 265 
Creating the Login.html Page...................................................................................................................... 266 
Creating the Send.html Page ....................................................................................................................... 266 
Creating the DriverConnection.java File.................................................................................................... 266 
Creating the UserDAO.java File.................................................................................................................. 267 
Creating the LoginServlet.java Servlet ....................................................................................................... 267 
Creating the Mail.java File ........................................................................................................................... 269 
Creating the MailsDAO.java File ................................................................................................................ 270 
Creating the InboxServlet.java Servlet ....................................................................................................... 271 
Creating the ViewMailServlet.java Servlet ................................................................................................ 272 
Creating the SendReplyServlet.java Servlet............................................................................................... 274 
Creating the Deployment Descriptor File.................................................................................................. 275 
Creating the Database Tables ...................................................................................................................... 276 
Creating the Directory Structure................................................................................................................. 277 
Running the Application.............................................................................................................................. 277 
Describing Cookies.................................................................................................................................................279
Listing the Advantages and Disadvantages of Cookies........................................................................... 280 
Considering the Situations to use Cookies ................................................................................................ 280 
Using Cookies .........................................................................................................................................................281
Creating the Home.html File ....................................................................................................................... 281 
Creating the AddCookieServlet.java File................................................................................................... 281 
Creating the GetCookieServlet.java File..................................................................................................... 282 
Creating the web.xml File ............................................................................................................................ 282 
Running the Application.............................................................................................................................. 283 
Exploring HttpSession ...........................................................................................................................................284
Creating a Session Object............................................................................................................................. 285 
Locating a Session Object Associated with the Current Request............................................................ 285 
Difference between the getSession() and getSession(Boolean) Methods...................................... 285 
Table of Contents
xv
Storing Information in a Session ................................................................................................................. 285 
Attaching the Session Identity to the URLs............................................................................................... 286 
Looking up Information in a Session.......................................................................................................... 287 
Discarding Completed or Abandoned Sessions........................................................................................ 287 
Listing the Advantages and Disadvantages of HttpSession.................................................................... 288 
Considering the Situations to use HttpSession ......................................................................................... 288 
Threading Issues of a Session............................................................................................................. 288 
Sessions in a Clustered Environment................................................................................................ 288 
Working with HttpSession....................................................................................................................................288
Creating the Login.html File........................................................................................................................ 289 
Creating the DriverConnection.java File.................................................................................................... 289 
Creating the UserDAO.java File.................................................................................................................. 290 
Creating the Product.java File ..................................................................................................................... 290 
Creating the ProductsDAO.java File .......................................................................................................... 291 
Creating the LoginServlet.java File............................................................................................................. 291 
Creating the UserHomeServlet.java File.................................................................................................... 292 
Creating the GetProductsServlet.java File ................................................................................................. 293 
Creating the AddProductServlet.java File ................................................................................................. 295 
Creating the GetCartDetailsServlet.java File............................................................................................. 297 
Creating the LogoutServlet.java File........................................................................................................... 298 
Creating the web.xml File ............................................................................................................................ 299 
Describing Servlet Context Attributes .................................................................................................................304
Context Attributes in a Distributed Container.......................................................................................... 304 
Differences Between Parameters and Attributes............................................................................. 304 
Describing Scopes of the Web Application Objects ...........................................................................................304
Exploring the Single Thread Model .....................................................................................................................305
Explaining the Need of Synchronization in Servlets................................................................................ 305 
Implementing SingleThreadModel............................................................................................................. 306 
Describing the ServletOutputStream Class.........................................................................................................307
Using ServletOutputStream......................................................................................................................... 307 
Summary..................................................................................................................................................................309
Exercise ....................................................................................................................................................................310
Chapter 9: Implementing Filters, Listeners, and Wrappers.......................... 311
Exploring Filters......................................................................................................................................................312 
Filter Interception Design Pattern............................................................................................................... 312 
Filter API ........................................................................................................................................................ 313 
The Filter Interface............................................................................................................................... 313 
The FilterConfig Interface................................................................................................................... 314 
The FilterChain Interface .................................................................................................................... 314 
Table of Contents
xvi
Working With Filters .................................................................................................................................... 314 
Creating the Home.html Page............................................................................................................ 315 
Creating the TestServlet.java File ...................................................................................................... 315 
Creating the MyFilter1.java File......................................................................................................... 315 
Creating the MyFilter2.java File......................................................................................................... 316 
Configuring the Filters Application .................................................................................................. 316 
Running the Application .................................................................................................................... 318 
Changes in Servlet 2.4 in Filter Configurations......................................................................................... 320 
Using Filters with the forward( ) and include( ) Methods ............................................................. 320 
Describing Listeners...............................................................................................................................................321 
Need of Event Programming and Importance of Listeners..................................................................... 321 
Types of Listeners ......................................................................................................................................... 321 
Describing the Listener Interfaces............................................................................................................... 322 
The ServletContextListener Interface................................................................................................ 323 
The ServletContextAttributeListener Interface................................................................................ 327 
The HttpSessionListener Interface..................................................................................................... 332 
The HttpSessionAttributeListener Interface .................................................................................... 332 
The HttpSessionBindingListener Interface....................................................................................... 337 
The HttpSessionActivationListener Interface .................................................................................. 340 
The ServletRequestListener Interface................................................................................................ 340 
The ServletRequestAttributeListener Interface................................................................................ 341 
Describing Wrappers .............................................................................................................................................341 
Need of Wrappers......................................................................................................................................... 341 
Types of Wrapper Classes............................................................................................................................ 341 
The ServletRequestWrapper Class .................................................................................................... 342
The ServletResponseWrapper Class.................................................................................................. 342
The HttpServletRequestWrapper Class............................................................................................ 343
The HttpServletResponseWrapper Class ......................................................................................... 343 
Using Wrappers............................................................................................................................................. 344 
Creating the Home.html Page............................................................................................................ 344 
Creating the TestServlet.java File ...................................................................................................... 344 
Creating the MyRequestWrapper.java File...................................................................................... 345 
Creating the MyResponseWrapper.java File.................................................................................... 345 
Creating the MyWrapperFilter.java File........................................................................................... 346 
Creating the Web.xml File.................................................................................................................. 346 
Deploying and Running the Application ......................................................................................... 347 
Applet to Servlet Communication........................................................................................................................348 
An Example Using Applet in Servlet.......................................................................................................... 348 
Summary..................................................................................................................................................................351 
Exercise ....................................................................................................................................................................351 
Table of Contents
xvii
Chapter 10: Introduction to JSP ..................................................................... 353
Understanding JSP ................................................................................................................................................. 354 
Advantages of JSP over Servlets ................................................................................................................. 355 
Introducing the Tag-Based Approach ........................................................................................................ 356 
Describing the JSP Architecture .................................................................................................................. 357 
JSP Model I architecture...................................................................................................................... 357 
Describing the JSP Life-Cycle................................................................................................................................ 358 
The Page Translation Stage.......................................................................................................................... 358 
The Compilation Stage ................................................................................................................................. 360 
The Loading & Initialization Stage ............................................................................................................. 360 
The Request Handling Stage........................................................................................................................ 361 
The Destroying Stage.................................................................................................................................... 361 
Creating Simple JSP Pages..................................................................................................................................... 361 
Summary.................................................................................................................................................................. 364 
Exercise .................................................................................................................................................................... 364 
Chapter 11: Working with JSP Basic Tags and Implicit Objects ................. 365
Exploring Scripting Tags ....................................................................................................................................... 366 
Types of Scripting Tags ................................................................................................................................ 366 
The Scriptlet Tag.................................................................................................................................. 366 
The Declarative Tag............................................................................................................................. 367 
The Expression Tag ............................................................................................................................. 367 
Working with JSP Scripting Tags................................................................................................................ 368 
Exploring Implicit Objects..................................................................................................................................... 370 
Features of Implicit Objects ......................................................................................................................... 370 
Types of Implicit Objects.............................................................................................................................. 370 
The request Object ............................................................................................................................... 371 
The response Object............................................................................................................................. 371 
The out Object ...................................................................................................................................... 371 
The page Object.................................................................................................................................... 371 
The pageContext Object...................................................................................................................... 371 
The application Object ........................................................................................................................ 371 
The session Object................................................................................................................................ 371 
The config Object ................................................................................................................................. 371 
The exception Object ........................................................................................................................... 371 
Working with Implicit Objects .................................................................................................................... 372 
Exploring Directive Tags ....................................................................................................................................... 376 
Types of Directive Tags................................................................................................................................ 377 
The Page Directive Tag ....................................................................................................................... 377 
The Include Directive.......................................................................................................................... 378 
Table of Contents
xviii
The Taglib Directive ............................................................................................................................ 378 
Working with JSP Directive Tags................................................................................................................ 379 
Summary.................................................................................................................................................................. 382 
Exercise .................................................................................................................................................................... 382 
Chapter 12: Working with JavaBeans and Action Tags in JSP ................... 383
What is JavaBean?..................................................................................................................................................384 
Advantages of using JavaBeans .................................................................................................................. 384 
Action Tags..............................................................................................................................................................384 
Describing the Include Tag .......................................................................................................................... 385 
Difference Between Include Directive and Include Action............................................................ 385 
Describing the Forward Tag ........................................................................................................................ 386 
Describing the Param Tag............................................................................................................................ 386 
name ...................................................................................................................................................... 387 
value ...................................................................................................................................................... 387 
Describing the useBean Tag......................................................................................................................... 390 
Describing the Attributes of the <jsp:useBean> Tag....................................................................... 390 
Using the <jsp:useBean> Tag Attributes .......................................................................................... 391 
Generating Servlets with the <jsp:useBean> Tag ............................................................................ 392 
Describing the setProperty Tag................................................................................................................... 393 
name ...................................................................................................................................................... 393 
property ................................................................................................................................................ 393 
value ...................................................................................................................................................... 394 
param .................................................................................................................................................... 394 
Describing the getProperty Tag................................................................................................................... 395 
The name Attribute ............................................................................................................................. 395 
The property Attribute........................................................................................................................ 395 
Plugin.............................................................................................................................................................. 395 
Params ............................................................................................................................................................ 396 
Fallback........................................................................................................................................................... 396 
Attribute ......................................................................................................................................................... 396 
Body................................................................................................................................................................ 397 
Element........................................................................................................................................................... 397 
Text.................................................................................................................................................................. 398 
Declaring a Bean in a JSP.......................................................................................................................................398 
Creating a Bean.............................................................................................................................................. 398 
Declaring the Bean in a JSP.......................................................................................................................... 399 
Accessing the Bean Properties..................................................................................................................... 399 
Generating Dynamic Content within a JSP................................................................................................ 400 
Deploying and Running Application ......................................................................................................... 401 
Table of Contents
xix
Summary..................................................................................................................................................................403 
Exercise ....................................................................................................................................................................404 
Chapter 13: Enhancing the JSP Tags Support .............................................. 405
Custom Tags............................................................................................................................................................406 
Need of Custom Tags ................................................................................................................................... 406 
Elements of Custom Tags............................................................................................................................. 407 
Tag Library Descriptor........................................................................................................................ 407 
Tag Handler.......................................................................................................................................... 408 
The Tag Extension API...........................................................................................................................................410 
Empty Tags..............................................................................................................................................................411 
Empty Tag Handler Life Cycle.................................................................................................................... 412 
Using Empty Tags......................................................................................................................................... 412 
Body Content Tag Interface...................................................................................................................................420 
Body Tag Handler Life Cycle ...................................................................................................................... 420 
Using BodyContent Tag .............................................................................................................................. 421 
Iteration tag Interface.............................................................................................................................................429 
Iteration Tag Handler Life Cycle................................................................................................................. 429 
Simple Tags .............................................................................................................................................................433 
Life Cycle of Simple Tag Handlers ............................................................................................................. 433 
Differences between Simple Tag and Classic Tag Handlers ................................................................... 435 
The TryCatchFinally Interface ..............................................................................................................................435 
Summary..................................................................................................................................................................436 
Exercise ....................................................................................................................................................................436 
Chapter 14: Understanding JSP Expression Language ............................... 437
Basic Syntax of using EL........................................................................................................................................438 
Types of EL Expressions............................................................................................................................... 438 
Immediate and Deferred Expressions............................................................................................... 439 
Value Expressions................................................................................................................................ 439 
Method Expressions............................................................................................................................ 440 
Tag Attribute Types...................................................................................................................................... 440 
Resolving EL Expressions ............................................................................................................................ 441 
Describing the EL Resolver Classes................................................................................................... 441 
EL Operators.................................................................................................................................................. 443 
Types of EL Operators ........................................................................................................................ 443 
An Example of Using EL Operators.................................................................................................. 444 
Implicit EL Objects........................................................................................................................................ 445 
Example 1 of Using Implicit EL Objects ........................................................................................... 447 
Example 2 of Using Implicit EL Objects ........................................................................................... 449 
Table of Contents
xx
Introducing Functions with EL.............................................................................................................................451 
Using EL Functions ................................................................................................................................................451 
Summary..................................................................................................................................................................453 
Exercise ....................................................................................................................................................................453 
Chapter 15: Implementing Internationalization ............................................. 455
Introducing Internationalization ..........................................................................................................................456 
Java and Internationalization................................................................................................................................456 
Describing the Locale Class ......................................................................................................................... 456 
Parameters of the Locale Object......................................................................................................... 457 
Using the Locale Class ........................................................................................................................ 457 
Describing the ResourceBundle Class ........................................................................................................ 458 
The PropertyResourceBundle Class.................................................................................................. 459 
The ListResourceBundle Class........................................................................................................... 461 
Internationalizing Web Applications...................................................................................................................463 
Creating the JSP Views................................................................................................................................. 464 
Creating the index.html View............................................................................................................ 464 
Creating the Home.jsp View .............................................................................................................. 464 
Creating the I18NServlet Class.................................................................................................................... 465 
Creating the Resource Bundles.................................................................................................................... 465 
Configuring the Application........................................................................................................................ 466 
Designing the Application Directory Structure ........................................................................................ 466 
Running the Application.............................................................................................................................. 467 
Summary..................................................................................................................................................................468 
Exercise ....................................................................................................................................................................468 
Chapter 16: Working with JSP Standard Tag Library (JSTL)....................... 469
Describing JSTL Core Tags....................................................................................................................................470 
General-Purpose Tags .................................................................................................................................. 470 
The <c:out> tag .................................................................................................................................... 470 
The <c:set> Tag .................................................................................................................................... 472 
The <c:remove> Tag............................................................................................................................ 473 
The <c:catch> Tag................................................................................................................................ 473 
Conditional and Looping Tags.................................................................................................................... 473 
Types of Conditional and Looping Tags .......................................................................................... 473 
Using Conditional and Looping Tags............................................................................................... 475 
Networking Tags........................................................................................................................................... 480 
The <c:import> Tag............................................................................................................................. 480 
The <c:url> Tag.................................................................................................................................... 480 
The <c:redirect> Tag............................................................................................................................ 481 
Table of Contents
xxi
The <c:param> Tag.............................................................................................................................. 481 
Describing the JSTL SQL Tags ..............................................................................................................................481 
Types of JSTL SQL Tags ............................................................................................................................... 481 
The <sql:query> Tag............................................................................................................................ 482 
The <sql:update> Tag ......................................................................................................................... 482 
The <sql:param> Tag .......................................................................................................................... 482 
The <sql:dateParam> Tag................................................................................................................... 483 
The <sql:setDataSource> Tag............................................................................................................. 483 
The <sql:transaction> Tag .................................................................................................................. 483 
Using JSTL SQL Tags.................................................................................................................................... 483 
JSTL Formatting Tags.............................................................................................................................................486 
Basic Formatting Tags .................................................................................................................................. 486 
Types of Basic Formatting Tags......................................................................................................... 486
Using Basic JSTL Formatting Tags .................................................................................................... 488 
Number Formatting Tags............................................................................................................................. 490 
Types of Number Formatting Tags ................................................................................................... 490 
Using Number Format Tags............................................................................................................... 491 
Date Formatting Tags ................................................................................................................................... 494 
Types of Date Formatting Tags.......................................................................................................... 494 
Using Date Formatting Tags .............................................................................................................. 495 
Time Zone Formatting Tags......................................................................................................................... 497 
Types of Time Zone Formatting Tags............................................................................................... 497
Using TimeZone Formatting Tags..................................................................................................... 497 
JSTL XML Tags .......................................................................................................................................................499 
XML Core Tags.............................................................................................................................................. 499 
The <x:parse> Tag ............................................................................................................................... 500 
The <x:out> Tag................................................................................................................................... 500 
The <x:set> Tag.................................................................................................................................... 500 
XML Flow Control Tags............................................................................................................................... 500 
The <x:if> Tag ...................................................................................................................................... 501
The <x:choose> Tag............................................................................................................................. 501
The <x:when> Tag............................................................................................................................... 501
The <x:otherwise> Tag........................................................................................................................ 501
The <x:forEach> tag ............................................................................................................................ 501 
XML Transformation Tags........................................................................................................................... 502 
The <x:transform> Tag........................................................................................................................ 502 
The <x:param> Tag ............................................................................................................................. 502 
Implementing JSTL Tags .......................................................................................................................................502 
Summary..................................................................................................................................................................506 
Exercise ....................................................................................................................................................................506 
adj
adj
adj
adj
adj

More Related Content

What's hot

LG Stylo 2 Owner's Manual (English)
LG Stylo 2 Owner's Manual (English)LG Stylo 2 Owner's Manual (English)
LG Stylo 2 Owner's Manual (English)
manualsheet
 
I showu hd pro manual
I showu hd pro manualI showu hd pro manual
I showu hd pro manualrudyroiz
 
AppLoader User Guide
AppLoader User GuideAppLoader User Guide
AppLoader User Guide
NRG Global
 
2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways
2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways
2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways
Zimbrick Buick/GMC West
 
ExTreM Expense Report Software
ExTreM Expense Report SoftwareExTreM Expense Report Software
ExTreM Expense Report Software
Lantech-Soft
 
Netex learningMaker | Author Guide v3.2 [En]
Netex learningMaker | Author Guide v3.2 [En]Netex learningMaker | Author Guide v3.2 [En]
Netex learningMaker | Author Guide v3.2 [En]
Netex Learning
 
Netex learningMaker | Basic Template v1.0 [En]
Netex learningMaker | Basic Template v1.0 [En]Netex learningMaker | Basic Template v1.0 [En]
Netex learningMaker | Basic Template v1.0 [En]Netex Learning
 
Netex learningMaker | Author Guide v3.1 [En]
Netex learningMaker | Author Guide v3.1 [En]Netex learningMaker | Author Guide v3.1 [En]
Netex learningMaker | Author Guide v3.1 [En]Netex Learning
 
Netex learningMaker | Author Manual v3.0 [En]
Netex learningMaker | Author Manual v3.0 [En]Netex learningMaker | Author Manual v3.0 [En]
Netex learningMaker | Author Manual v3.0 [En]Netex Learning
 
Case cx490 d (tier4 final) crawler excavator service repair manual
Case cx490 d (tier4 final) crawler excavator service repair manualCase cx490 d (tier4 final) crawler excavator service repair manual
Case cx490 d (tier4 final) crawler excavator service repair manual
fusjejfskekfmsme
 
Case cx490 d (tier4 final) crawler excavator service repair manual instant do...
Case cx490 d (tier4 final) crawler excavator service repair manual instant do...Case cx490 d (tier4 final) crawler excavator service repair manual instant do...
Case cx490 d (tier4 final) crawler excavator service repair manual instant do...
uuufjjsjekkem
 
MFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document GuideMFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document Guide
Vinh Nguyen
 

What's hot (14)

Manual
ManualManual
Manual
 
LG Stylo 2 Owner's Manual (English)
LG Stylo 2 Owner's Manual (English)LG Stylo 2 Owner's Manual (English)
LG Stylo 2 Owner's Manual (English)
 
I showu hd pro manual
I showu hd pro manualI showu hd pro manual
I showu hd pro manual
 
AppLoader User Guide
AppLoader User GuideAppLoader User Guide
AppLoader User Guide
 
2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways
2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways
2011 GMC Savana Upfitting Wisconsin - Full Size Vans & Cutaways
 
ExTreM Expense Report Software
ExTreM Expense Report SoftwareExTreM Expense Report Software
ExTreM Expense Report Software
 
Netex learningMaker | Author Guide v3.2 [En]
Netex learningMaker | Author Guide v3.2 [En]Netex learningMaker | Author Guide v3.2 [En]
Netex learningMaker | Author Guide v3.2 [En]
 
Netex learningMaker | Basic Template v1.0 [En]
Netex learningMaker | Basic Template v1.0 [En]Netex learningMaker | Basic Template v1.0 [En]
Netex learningMaker | Basic Template v1.0 [En]
 
Netex learningMaker | Author Guide v3.1 [En]
Netex learningMaker | Author Guide v3.1 [En]Netex learningMaker | Author Guide v3.1 [En]
Netex learningMaker | Author Guide v3.1 [En]
 
Threading
ThreadingThreading
Threading
 
Netex learningMaker | Author Manual v3.0 [En]
Netex learningMaker | Author Manual v3.0 [En]Netex learningMaker | Author Manual v3.0 [En]
Netex learningMaker | Author Manual v3.0 [En]
 
Case cx490 d (tier4 final) crawler excavator service repair manual
Case cx490 d (tier4 final) crawler excavator service repair manualCase cx490 d (tier4 final) crawler excavator service repair manual
Case cx490 d (tier4 final) crawler excavator service repair manual
 
Case cx490 d (tier4 final) crawler excavator service repair manual instant do...
Case cx490 d (tier4 final) crawler excavator service repair manual instant do...Case cx490 d (tier4 final) crawler excavator service repair manual instant do...
Case cx490 d (tier4 final) crawler excavator service repair manual instant do...
 
MFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document GuideMFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document Guide
 

Similar to adj

Diamond
DiamondDiamond
Diamond
NeverLandLuna
 
Tortoise svn 1.7-en
Tortoise svn 1.7-enTortoise svn 1.7-en
Tortoise svn 1.7-en
sreeharichepuri
 
Link Resources Past Performance Summaries
Link Resources Past Performance SummariesLink Resources Past Performance Summaries
Link Resources Past Performance SummariesLink Resources
 
Link SDVOSB Past Performance Summaries
Link SDVOSB Past Performance SummariesLink SDVOSB Past Performance Summaries
Link SDVOSB Past Performance Summaries
gasanden
 
Link SDVOSB Past Performance Summaries
Link SDVOSB Past Performance SummariesLink SDVOSB Past Performance Summaries
Link SDVOSB Past Performance Summaries
gasanden
 
Getting started in_enterprise_architect
Getting started in_enterprise_architectGetting started in_enterprise_architect
Getting started in_enterprise_architectmistmoon
 
M Daemon E Mail Server Manual
M Daemon E Mail Server ManualM Daemon E Mail Server Manual
M Daemon E Mail Server Manualguestcf19c83
 
Dynamics AX/ X++
Dynamics AX/ X++Dynamics AX/ X++
Dynamics AX/ X++
Reham Maher El-Safarini
 
GUIA REFERENCIA EZSTEER PARA EZ250
GUIA REFERENCIA EZSTEER PARA EZ250GUIA REFERENCIA EZSTEER PARA EZ250
GUIA REFERENCIA EZSTEER PARA EZ250Pablo Cea Campos
 
2 x applicationserver
2 x applicationserver2 x applicationserver
2 x applicationserver
Teberite Ramos
 
Win plc engine-en
Win plc engine-enWin plc engine-en
Win plc engine-en
dreamtech2
 
WebHost Manager User Manual
WebHost Manager User ManualWebHost Manager User Manual
WebHost Manager User Manualwebhostingguy
 
WebHost Manager User Manual
WebHost Manager User ManualWebHost Manager User Manual
WebHost Manager User Manualwebhostingguy
 
Java : How to Program - 7e
Java : How to Program - 7eJava : How to Program - 7e
Java : How to Program - 7eCHIH-PEI WEN
 
Java how to_program__7th_edition
Java how to_program__7th_editionJava how to_program__7th_edition
Java how to_program__7th_edition
ABDUmomo
 
ARQUIVO ROUBADO
ARQUIVO ROUBADOARQUIVO ROUBADO
ARQUIVO ROUBADO
D813061988
 
Netex learningMaker | Multipage Template v2.5.3 [En]
Netex learningMaker | Multipage Template v2.5.3 [En]Netex learningMaker | Multipage Template v2.5.3 [En]
Netex learningMaker | Multipage Template v2.5.3 [En]Netex Learning
 
Albpm60 studio reference_guide
Albpm60 studio reference_guideAlbpm60 studio reference_guide
Albpm60 studio reference_guideVibhor Rastogi
 

Similar to adj (20)

Diamond
DiamondDiamond
Diamond
 
Tortoise svn 1.7-en
Tortoise svn 1.7-enTortoise svn 1.7-en
Tortoise svn 1.7-en
 
Link Resources Past Performance Summaries
Link Resources Past Performance SummariesLink Resources Past Performance Summaries
Link Resources Past Performance Summaries
 
Link SDVOSB Past Performance Summaries
Link SDVOSB Past Performance SummariesLink SDVOSB Past Performance Summaries
Link SDVOSB Past Performance Summaries
 
Link SDVOSB Past Performance Summaries
Link SDVOSB Past Performance SummariesLink SDVOSB Past Performance Summaries
Link SDVOSB Past Performance Summaries
 
Getting started in_enterprise_architect
Getting started in_enterprise_architectGetting started in_enterprise_architect
Getting started in_enterprise_architect
 
An introduction-to-tkinter
An introduction-to-tkinterAn introduction-to-tkinter
An introduction-to-tkinter
 
M Daemon E Mail Server Manual
M Daemon E Mail Server ManualM Daemon E Mail Server Manual
M Daemon E Mail Server Manual
 
Dynamics AX/ X++
Dynamics AX/ X++Dynamics AX/ X++
Dynamics AX/ X++
 
GUIA REFERENCIA EZSTEER PARA EZ250
GUIA REFERENCIA EZSTEER PARA EZ250GUIA REFERENCIA EZSTEER PARA EZ250
GUIA REFERENCIA EZSTEER PARA EZ250
 
2 x applicationserver
2 x applicationserver2 x applicationserver
2 x applicationserver
 
Win plc engine-en
Win plc engine-enWin plc engine-en
Win plc engine-en
 
WebHost Manager User Manual
WebHost Manager User ManualWebHost Manager User Manual
WebHost Manager User Manual
 
WebHost Manager User Manual
WebHost Manager User ManualWebHost Manager User Manual
WebHost Manager User Manual
 
Java : How to Program - 7e
Java : How to Program - 7eJava : How to Program - 7e
Java : How to Program - 7e
 
Java how to_program__7th_edition
Java how to_program__7th_editionJava how to_program__7th_edition
Java how to_program__7th_edition
 
ARQUIVO ROUBADO
ARQUIVO ROUBADOARQUIVO ROUBADO
ARQUIVO ROUBADO
 
Netex learningMaker | Multipage Template v2.5.3 [En]
Netex learningMaker | Multipage Template v2.5.3 [En]Netex learningMaker | Multipage Template v2.5.3 [En]
Netex learningMaker | Multipage Template v2.5.3 [En]
 
C2675m c
C2675m cC2675m c
C2675m c
 
Albpm60 studio reference_guide
Albpm60 studio reference_guideAlbpm60 studio reference_guide
Albpm60 studio reference_guide
 

Recently uploaded

一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 

Recently uploaded (20)

一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 

adj

  • 1. Table of Contents Introduction..............................................................................................…….xxix Chapter 1: Getting Started with Web Applications in Java ...............................1 Introduction to Web Applications............................................................................................................................2 Benefits of Web Applications....................................................................................................................................5 Technologies used in Web Applications..................................................................................................................5 Describing JDBC................................................................................................................................................ 5 Exploring the JDBC Architecture........................................................................................................... 6  Describing Java Servlets................................................................................................................................... 7 Advantages of Java Servlets................................................................................................................... 8  Describing JSP.................................................................................................................................................... 8 Request Processing of a JSP Page .......................................................................................................... 9 Describing the JSP Life-cycle.................................................................................................................. 9  Introduction to Web Architecture Models ............................................................................................................10 Describing the Model-1 Architecture ........................................................................................................... 10 Limitations of the Model-1 Architecture ............................................................................................ 11  Describing the Model-2 Architecture ........................................................................................................... 11 Advantages of the Model-2 Architecture ........................................................................................... 12  Introduction to the MVC Architecture...................................................................................................................12 Describing the Model Component................................................................................................................ 13 Describing the View Component.................................................................................................................. 13 Describing the Controller Component ......................................................................................................... 13 Summary....................................................................................................................................................................14 Exercise ......................................................................................................................................................................14 Chapter 2: Getting Started with JDBC ..............................................................15 Introducing ODBC....................................................................................................................................................16 Defining ODBC.........................................................................................................................................................16 Listing Features of ODBC .............................................................................................................................. 17
  • 2. Table of Contents vi Describing the ODBC Components .............................................................................................................. 17 The Application Component................................................................................................................ 18  The DriverManager Component ......................................................................................................... 18  The Driver Component......................................................................................................................... 18  The Datasource Component................................................................................................................. 19  Describing the ODBC Architecture............................................................................................................... 19 The Single-tier ODBC Architecture..................................................................................................... 19  The Multiple-tier ODBC Architecture................................................................................................. 20  Introducing JDBC .....................................................................................................................................................20 Describing Components of JDBC.................................................................................................................. 22 Listing Features of JDBC ................................................................................................................................ 22 Listing New Features in JDBC 4.0................................................................................................................. 24 Exploring the JDBC Architecture............................................................................................................................25 The Type-1 Driver........................................................................................................................................... 26 Advantages of the Type-1 Driver ........................................................................................................ 27  Disadvantages of the Type-1 Driver ................................................................................................... 27  Situations to Use the Type-1 Driver .................................................................................................... 27  The Type-2 Driver (Java to native API)........................................................................................................ 27 Advantages of the Type-2 Driver ........................................................................................................ 28  Disadvantages of the Type-2 Driver ................................................................................................... 28  Examples of the Type-2 Driver ............................................................................................................ 28  Situations to Use the Type-2 Driver .................................................................................................... 28  The Type-3 Driver (Java to Network Protocol/All Java Driver)............................................................... 29 Advantages of the Type-3 Driver ........................................................................................................ 29  Disadvantages of the Type-3 Driver ................................................................................................... 29  Examples of the Type-3 Driver ............................................................................................................ 29  Situations to Use the Type-3 Driver .................................................................................................... 30  The Type-4 Driver (Java to Database protocol)........................................................................................... 30 Advantages of the Type-4 Driver ........................................................................................................ 30  Disadvantage of the Type-4 Driver ..................................................................................................... 30  Examples of the Type-4 Driver ............................................................................................................ 31  Summary....................................................................................................................................................................31 Exercise ......................................................................................................................................................................32 State True or False ....................................................................................................................................................32  Chapter 3: Working with JDBC APIs.................................................................33 Introducing JDBC API..............................................................................................................................................34 Explaining the Types of JDBC APIs.............................................................................................................. 35  The JDBC Core API ............................................................................................................................... 35  The JDBC Extension API....................................................................................................................... 36 
  • 3. Table of Contents vii Listing the New APIs Added to JDBC 4.0.................................................................................................... 37  Describing the Major Classes and Interfaces............................................................................................... 38  The DriverManager Class..................................................................................................................... 38  The Driver Interface .............................................................................................................................. 39  The Connection Interface...................................................................................................................... 40  The Statement Interface ........................................................................................................................ 42  Communicating with Databases by using JDBC APIs.........................................................................................45 Step 1: Obtaining a Connection..................................................................................................................... 46  Obtaining an Connection using Driver object.................................................................................... 46  Step 1.i: Registering a Driver object with DriverManager................................................................ 47  Step 1.ii: Establishing a Connection using DriverManager.............................................................. 48  Step 2: Creating a JDBC Statement Object ................................................................................................... 49  Step 3: Executing SQL Statements................................................................................................................. 49  Step 4: Closing the Connection...................................................................................................................... 49  Creating a Simple Application................................................................................................................................50 Configuring the Application.......................................................................................................................... 51  Creating a Table..................................................................................................................................... 51  Creating a DSN................................................................................................................................................ 51  Understanding Various JDBC Drivers...................................................................................................................53 The OCI8 Driver for Oracle............................................................................................................................ 54  The IDS Driver................................................................................................................................................. 54  Installing the IDS Server ....................................................................................................................... 54  Configuring IDS Driver ........................................................................................................................ 57  The Thin driver for Oracle ............................................................................................................................. 57  Summary....................................................................................................................................................................58 Exercise ......................................................................................................................................................................58 Fill in the blanks with appropriate words or phrases:.........................................................................................58 Chapter 4: Implementing JDBC Statements and ResultSets ..........................59 Describing JDBC Statement.....................................................................................................................................60 Working with the Statement Interface...................................................................................................................60 Exploring the Methods of Statement ............................................................................................................ 60  The executeUpdate (String sqlStatement) Method............................................................................ 61  The executeQuery (String query) Method.......................................................................................... 61  The execute (String sqlStatement) Method......................................................................................... 61  The getResultSet () Method .................................................................................................................. 62  The getUpdateCount () Method .......................................................................................................... 62  Using Statement .............................................................................................................................................. 62  Creating a Table..................................................................................................................................... 62  Inserting a Row...................................................................................................................................... 64 
  • 4. Table of Contents viii Working with the PreparedStatement Interface...................................................................................................65 Comparing Statement and PreparedStatement Objects............................................................................. 66  Describing the setXXX methods of PreparedStatement............................................................................. 67  Listing the Advantages and Disadvantages of PreparedStatement ......................................................... 69  Using PreparedStatement .............................................................................................................................. 69  Creating a PreparedStatement Object................................................................................................. 69  Setting the Values for Parameters........................................................................................................ 70  Executing the PreparedStatement ....................................................................................................... 70  Using PreparedStatement with Parameters................................................................................................. 70  Exploring the Usage of the PreparedStatement Object .............................................................................. 73  Working with the CallableStatement Interface.....................................................................................................73 Describing Stored Procedures ....................................................................................................................... 73  Listing the Benefits of Working with a Stored Procedure ......................................................................... 74  Using CallableStatement ................................................................................................................................ 74  Creating the CallableStatement object ................................................................................................ 74  Setting the Values of the Parameters................................................................................................... 75  Registering the OUT Parameter Type................................................................................................. 75  Executing the Stored Procedure or Function ..................................................................................... 75  Retrieving the Parameter Values ......................................................................................................... 75  Using CallableStatement with Parameters .................................................................................................. 75  Executing a Stored Procedure with IN Parameters........................................................................... 75  Executing a Stored Procedure with OUT Parameters....................................................................... 77  Calling Functions by Using CallableStatement........................................................................................... 79  Using Cursors in CallableStatement............................................................................................................. 81  Comparing Procedure and Function ............................................................................................................ 82  Working with the ResultSet Interface ....................................................................................................................82 Describing the Methods of ResultSet............................................................................................................ 83  Using ResultSet................................................................................................................................................ 85  Moving the Cursor Position ................................................................................................................. 86  Reading the Column Values................................................................................................................. 86  Retrieving All the Rows from a Table .......................................................................................................... 89  Retrieving a Particular Column Using ResultSet........................................................................................ 91  Handling NULL Values...........................................................................................................................................94 Working with the ResultSetMetaData Interface...................................................................................................95 Describing ResultSetMetaData...................................................................................................................... 95  Using ResultSetMetaData .............................................................................................................................. 96  Creating SQLEditor in Java.....................................................................................................................................98 Creating the Command-Based SQLEditor................................................................................................... 98  Creating the Windows-Based SQLEditor................................................................................................... 100 
  • 5. Table of Contents ix Using Advanced Concepts of ResultSet ..............................................................................................................104 Exploring Characteristics of the ResultSet Object..................................................................................... 104  ResultSet Types.................................................................................................................................... 104  ResultSet Concurrency........................................................................................................................ 105  ResultSet Holdability .......................................................................................................................... 106  Setting the ResultSet Type and ResultSet Concurrency........................................................................... 106  Using ResultSet Objects to Manipulate Data............................................................................................. 112  Using the ResultSet Object to Update Data...................................................................................... 112  Using the ResultSet Object to Delete a Row..................................................................................... 114  Using a ResultSet Object to Insert a Row.......................................................................................... 116  Closing the Connection..........................................................................................................................................118 Closing the Statement and ResultSet.......................................................................................................... 118  Working with the DatabaseMetaData Interface .................................................................................................119 Retrieving Database and Driver Details..................................................................................................... 121  Retrieving Table Description....................................................................................................................... 122  Retrieving Column Details........................................................................................................................... 124  Retrieving Data from a Microsoft Excel Sheet........................................................................................... 125  Summary..................................................................................................................................................................128 Exercise ....................................................................................................................................................................129 Chapter 5: Describing Advanced JDBC Concepts.........................................131 Exploring the SQL 99 Data Types.........................................................................................................................132 The BLOB Data Type .................................................................................................................................... 132  Storing BLOB Values........................................................................................................................... 133  Reading BLOB Values......................................................................................................................... 135  The CLOB Data Type.................................................................................................................................... 136  Storing CLOB Values .......................................................................................................................... 137  Reading CLOB Values......................................................................................................................... 138  The Struct (Object) Data Type ..................................................................................................................... 140  Using User-Defined Object Types in Java to Represent Database Object Types......................... 140  Creating a JDBC UDT.......................................................................................................................... 141  Mapping the JDBC UDT..................................................................................................................... 141  Implementing UDT ............................................................................................................................. 141  Using the java.sql.Struct Interface ..................................................................................................... 145  The Array Data Type .................................................................................................................................... 146  The Ref Data Type......................................................................................................................................... 151  Working with the ROWID Type...........................................................................................................................151 Working with Batch Updates................................................................................................................................152 Using Batch Updates with the Statement Object ...................................................................................... 153  The Batch Update Methods................................................................................................................ 153 
  • 6. Table of Contents x The BatchUpdateException Exception.............................................................................................. 154  Using Batch Updates with the PreparedStatement Object ...................................................................... 156  Describing SQL/XML and XML support............................................................................................................157 Retrieving Auto Generated Keys..........................................................................................................................158 Working with RowSets in JDBC ...........................................................................................................................161 The Connected RowSets............................................................................................................................... 161  The Disconnected RowSets.......................................................................................................................... 161  Using the RowSet at Design Time............................................................................................................... 162  Setting the Properties of the RowSet Instance ................................................................................. 162  Working with RowSet Events ............................................................................................................ 162  Using RowSets at Run Time ........................................................................................................................ 162  Setting Parameter Values of a RowSet Object.................................................................................. 163  Executing RowSets .............................................................................................................................. 163  Traversing a RowSet............................................................................................................................ 163  Exploring Connection Pooling..............................................................................................................................163 Working with Connection Pool ............................................................................................................................165 Working with Transactions...................................................................................................................................166 Describing ACID Properties ........................................................................................................................ 166  Atomicity .............................................................................................................................................. 167  Consistency........................................................................................................................................... 167  Isolation................................................................................................................................................. 167  Durability.............................................................................................................................................. 167  Types of Transactions................................................................................................................................... 167  Performing Transaction Management........................................................................................................ 168  Describing the Wrapper Interface ........................................................................................................................171 The isWrapperFor() Method........................................................................................................................ 171  The unwrap() Method .................................................................................................................................. 171  Describing SQLException......................................................................................................................................171 Summary..................................................................................................................................................................173 Exercise ....................................................................................................................................................................174 Chapter 6: Understanding Java Servlet ..........................................................175 Understanding the Need for Server-Side Extensions ........................................................................................176 Introducing CGI......................................................................................................................................................176 Introducing Java Servlet ........................................................................................................................................178 Advantages of a Servlet................................................................................................................................ 178  New Features of Servlet 2.5.......................................................................................................................... 178  Exploring the Servlet Container ...........................................................................................................................180 Describing the Request Processing Mechanism........................................................................................ 180  Describing the Types of Servlet Container Configurations..................................................................... 180 
  • 7. Table of Contents xi The Standalone Container .................................................................................................................. 181  The In-Process Container.................................................................................................................... 181  The Out-Process Containers............................................................................................................... 182  Introducing the Servlet API...................................................................................................................................182 Describing the javax.servlet Package.......................................................................................................... 183  Describing the javax.servlet.http Package.................................................................................................. 184  Implementing a Servlet Object..............................................................................................................................185 The javax.servlet.Servlet Interface............................................................................................................... 185  The javax.servlet.ServletConfig Interface<H2>......................................................................................... 185  Understanding the Servlet LifeCycle ...................................................................................................................186 Describing the Stages of the Servlet LifeCycle .......................................................................................... 186  Loading a Servlet ................................................................................................................................. 186  Initializing a Servlet............................................................................................................................. 187  Handling Request................................................................................................................................ 187  Destroying a Servlet (End of service)................................................................................................ 189  Exploring the Servlet Life Cycle Methods ................................................................................................. 189  The init () method ................................................................................................................................ 189  The service( ) Method.......................................................................................................................... 189  The destroy () Method......................................................................................................................... 190  Developing the First Servlet Application ............................................................................................................190 Creating the home.html Page ...................................................................................................................... 190  Creating the LifeCycleServlet...................................................................................................................... 191  Creating the Deployment Descriptor ......................................................................................................... 191  Deploying Web Application........................................................................................................................ 192  Running the LifeCycle Application ............................................................................................................ 193  Understanding the Request Processing Workflow ............................................................................................194 Request Navigation....................................................................................................................................... 195  Request Delegation ....................................................................................................................................... 196  Working with the GenericServlet Class...............................................................................................................197 Exploring Methods of the GenericServlet Class ...................................................................................... 198  Using the GenericServlet Class .................................................................................................................. 199  Creating the Home.html Page............................................................................................................ 199  Developing the HelloServlet.java Servlet......................................................................................... 200  Deploying and Running the Application ......................................................................................... 200  Summary..................................................................................................................................................................201 Exercise ....................................................................................................................................................................202 Chapter 7: Understanding Request Processing and HTTP...........................203 Implementing the ServletRequest Interface........................................................................................................204 Managing the Servlet Object as a Throwaway Object.............................................................................. 204 
  • 8. Table of Contents xii Managing the ServletRequest Object Pool................................................................................................. 204  Working with Request Parameters............................................................................................................. 205  Creating the Login Form..................................................................................................................... 206  Creating the LoginServlet Servlet...................................................................................................... 206  Creating the Deployment Descriptor File......................................................................................... 208  Running the Application .................................................................................................................... 209  Working with Initialization Parameters ..............................................................................................................210 Exploring the Need for Initialization Parameters..................................................................................... 211  Retrieving Initialization Parameters........................................................................................................... 211  Handling Servlet Initialization Parameters ............................................................................................... 212  Creating the Home.html File.............................................................................................................. 212  Creating the InitParamsServlet Servlet............................................................................................. 212  Creating the Deployment Descriptor File......................................................................................... 213  Running the Application .................................................................................................................... 214  Working with Context Initialization Parameters................................................................................................216 Retrieving Context Initialization Parameters ............................................................................................ 216  Using Context Initialization Parameters .................................................................................................... 216  Creating the Home.html File.............................................................................................................. 217  Creating the Login.html File .............................................................................................................. 217  Creating the Register.html File .......................................................................................................... 218  Creating the RegistrationServlet Servlet........................................................................................... 219  Creating the LoginServlet Servlet...................................................................................................... 221  Creating the Deployment Descriptor File......................................................................................... 223  Running the Application .................................................................................................................... 225  Understanding ServletResponse...........................................................................................................................227 Understanding Request Dispatching...................................................................................................................228 Navigation...................................................................................................................................................... 229  Delegation ...................................................................................................................................................... 230  Dispatching the Request........................................................................................................................................230 Getting a RequestDispatcher object............................................................................................................ 230  The getRequestDispatcher() Method of ServletContext ................................................................. 230  The getNamedDispatcher() Method of ServletContext .................................................................. 231  The getRequestDispatcher() Method of ServletRequest................................................................. 231  Comparing the getRequestDispatcher() Methods of ServletContext and ServletRequest......... 231  Comparing the getRequestDispatcher() & getNamedDispatcher() Methods.............................. 232  Understanding the include() and forward() Methods of RequestDispatcher ....................................... 232  Describing the include() Method....................................................................................................... 232  Describing the forward() Method...................................................................................................... 234  Comparing the include() and forward() Methods........................................................................... 235 
  • 9. Table of Contents xiii Considering the Situations to use the include() and forward() Methods..................................... 236  Working with RequestDispatcher............................................................................................................... 236  Creating the Home.html File.............................................................................................................. 236  Creating the TestServlet1 Servlet....................................................................................................... 237  Creating the TestServlet2 Servlet....................................................................................................... 238  Creating the Deployment Descriptor File......................................................................................... 239  Running the Application .................................................................................................................... 240  Describing Request Attributes..............................................................................................................................242 Working with Request Attributes............................................................................................................... 242  Creating the Home.html File.............................................................................................................. 243  Creating the ValidationServlet Servlet.............................................................................................. 243  Creating the AddServlet Servlet ........................................................................................................ 244  Creating the SubServlet Servlet ......................................................................................................... 244  Creating the ResponseServlet Servlet ............................................................................................... 245  Creating the Deployment Descriptor File......................................................................................... 246  Running the Application .................................................................................................................... 247  Describing HTTP Basic ..........................................................................................................................................249 Describing HTTP Status Codes ................................................................................................................... 249  1XX – Informational ............................................................................................................................ 249  2XX – Success ....................................................................................................................................... 249  3XX – Redirection ................................................................................................................................ 249  4XX – Client Error................................................................................................................................ 250  5XX – Server Error ............................................................................................................................... 250  Describing the HttpServletRequest & HttpServletResponse Interfaces ..........................................................250 Working with HttpServletRequest ............................................................................................................. 251  Working with HttpServletResponse........................................................................................................... 251  Exploring the Methods for Response Headers ................................................................................ 252  Exploring the Methods for Buffering................................................................................................ 253  Comparing RequestDispatcher forward and sendRedirect........................................................... 253  Handling the HttpServletRequest and HttpServletResponse Interfaces ............................................... 254  Creating the Home.html File.............................................................................................................. 254  Creating the HttpServletRequestEx Servlet ..................................................................................... 254  Creating the Deployment Descriptor File......................................................................................... 255  Running the Application .................................................................................................................... 256  Describing HttpServlet...........................................................................................................................................258 The HttpServlet Lifecycle............................................................................................................................. 259  Summary..................................................................................................................................................................259 Exercise ....................................................................................................................................................................260
  • 10. Table of Contents xiv Chapter 8: Handling Sessions in Servlet ........................................................261 Introducing Session Tracking ...............................................................................................................................262 Describing URL Rewriting ....................................................................................................................................263 Using Query String for URL Rewriting...................................................................................................... 263  Using Path Info for URL Rewriting ............................................................................................................ 263  Listing the Disadvantages of URL Rewriting............................................................................................ 264  Considering Situations to use URL Rewriting .......................................................................................... 264  Exploring Hidden Form Field...............................................................................................................................264 Listing the Advantages and Disadvantages of Hidden Form Field ....................................................... 265  Considering the Situations to use Hidden Form Fields ........................................................................... 265  Working with URL Rewriting and Hidden Form Field ....................................................................................265 Creating the SiteHome.html Page............................................................................................................... 265  Creating the Login.html Page...................................................................................................................... 266  Creating the Send.html Page ....................................................................................................................... 266  Creating the DriverConnection.java File.................................................................................................... 266  Creating the UserDAO.java File.................................................................................................................. 267  Creating the LoginServlet.java Servlet ....................................................................................................... 267  Creating the Mail.java File ........................................................................................................................... 269  Creating the MailsDAO.java File ................................................................................................................ 270  Creating the InboxServlet.java Servlet ....................................................................................................... 271  Creating the ViewMailServlet.java Servlet ................................................................................................ 272  Creating the SendReplyServlet.java Servlet............................................................................................... 274  Creating the Deployment Descriptor File.................................................................................................. 275  Creating the Database Tables ...................................................................................................................... 276  Creating the Directory Structure................................................................................................................. 277  Running the Application.............................................................................................................................. 277  Describing Cookies.................................................................................................................................................279 Listing the Advantages and Disadvantages of Cookies........................................................................... 280  Considering the Situations to use Cookies ................................................................................................ 280  Using Cookies .........................................................................................................................................................281 Creating the Home.html File ....................................................................................................................... 281  Creating the AddCookieServlet.java File................................................................................................... 281  Creating the GetCookieServlet.java File..................................................................................................... 282  Creating the web.xml File ............................................................................................................................ 282  Running the Application.............................................................................................................................. 283  Exploring HttpSession ...........................................................................................................................................284 Creating a Session Object............................................................................................................................. 285  Locating a Session Object Associated with the Current Request............................................................ 285  Difference between the getSession() and getSession(Boolean) Methods...................................... 285 
  • 11. Table of Contents xv Storing Information in a Session ................................................................................................................. 285  Attaching the Session Identity to the URLs............................................................................................... 286  Looking up Information in a Session.......................................................................................................... 287  Discarding Completed or Abandoned Sessions........................................................................................ 287  Listing the Advantages and Disadvantages of HttpSession.................................................................... 288  Considering the Situations to use HttpSession ......................................................................................... 288  Threading Issues of a Session............................................................................................................. 288  Sessions in a Clustered Environment................................................................................................ 288  Working with HttpSession....................................................................................................................................288 Creating the Login.html File........................................................................................................................ 289  Creating the DriverConnection.java File.................................................................................................... 289  Creating the UserDAO.java File.................................................................................................................. 290  Creating the Product.java File ..................................................................................................................... 290  Creating the ProductsDAO.java File .......................................................................................................... 291  Creating the LoginServlet.java File............................................................................................................. 291  Creating the UserHomeServlet.java File.................................................................................................... 292  Creating the GetProductsServlet.java File ................................................................................................. 293  Creating the AddProductServlet.java File ................................................................................................. 295  Creating the GetCartDetailsServlet.java File............................................................................................. 297  Creating the LogoutServlet.java File........................................................................................................... 298  Creating the web.xml File ............................................................................................................................ 299  Describing Servlet Context Attributes .................................................................................................................304 Context Attributes in a Distributed Container.......................................................................................... 304  Differences Between Parameters and Attributes............................................................................. 304  Describing Scopes of the Web Application Objects ...........................................................................................304 Exploring the Single Thread Model .....................................................................................................................305 Explaining the Need of Synchronization in Servlets................................................................................ 305  Implementing SingleThreadModel............................................................................................................. 306  Describing the ServletOutputStream Class.........................................................................................................307 Using ServletOutputStream......................................................................................................................... 307  Summary..................................................................................................................................................................309 Exercise ....................................................................................................................................................................310 Chapter 9: Implementing Filters, Listeners, and Wrappers.......................... 311 Exploring Filters......................................................................................................................................................312  Filter Interception Design Pattern............................................................................................................... 312  Filter API ........................................................................................................................................................ 313  The Filter Interface............................................................................................................................... 313  The FilterConfig Interface................................................................................................................... 314  The FilterChain Interface .................................................................................................................... 314 
  • 12. Table of Contents xvi Working With Filters .................................................................................................................................... 314  Creating the Home.html Page............................................................................................................ 315  Creating the TestServlet.java File ...................................................................................................... 315  Creating the MyFilter1.java File......................................................................................................... 315  Creating the MyFilter2.java File......................................................................................................... 316  Configuring the Filters Application .................................................................................................. 316  Running the Application .................................................................................................................... 318  Changes in Servlet 2.4 in Filter Configurations......................................................................................... 320  Using Filters with the forward( ) and include( ) Methods ............................................................. 320  Describing Listeners...............................................................................................................................................321  Need of Event Programming and Importance of Listeners..................................................................... 321  Types of Listeners ......................................................................................................................................... 321  Describing the Listener Interfaces............................................................................................................... 322  The ServletContextListener Interface................................................................................................ 323  The ServletContextAttributeListener Interface................................................................................ 327  The HttpSessionListener Interface..................................................................................................... 332  The HttpSessionAttributeListener Interface .................................................................................... 332  The HttpSessionBindingListener Interface....................................................................................... 337  The HttpSessionActivationListener Interface .................................................................................. 340  The ServletRequestListener Interface................................................................................................ 340  The ServletRequestAttributeListener Interface................................................................................ 341  Describing Wrappers .............................................................................................................................................341  Need of Wrappers......................................................................................................................................... 341  Types of Wrapper Classes............................................................................................................................ 341  The ServletRequestWrapper Class .................................................................................................... 342 The ServletResponseWrapper Class.................................................................................................. 342 The HttpServletRequestWrapper Class............................................................................................ 343 The HttpServletResponseWrapper Class ......................................................................................... 343  Using Wrappers............................................................................................................................................. 344  Creating the Home.html Page............................................................................................................ 344  Creating the TestServlet.java File ...................................................................................................... 344  Creating the MyRequestWrapper.java File...................................................................................... 345  Creating the MyResponseWrapper.java File.................................................................................... 345  Creating the MyWrapperFilter.java File........................................................................................... 346  Creating the Web.xml File.................................................................................................................. 346  Deploying and Running the Application ......................................................................................... 347  Applet to Servlet Communication........................................................................................................................348  An Example Using Applet in Servlet.......................................................................................................... 348  Summary..................................................................................................................................................................351  Exercise ....................................................................................................................................................................351 
  • 13. Table of Contents xvii Chapter 10: Introduction to JSP ..................................................................... 353 Understanding JSP ................................................................................................................................................. 354  Advantages of JSP over Servlets ................................................................................................................. 355  Introducing the Tag-Based Approach ........................................................................................................ 356  Describing the JSP Architecture .................................................................................................................. 357  JSP Model I architecture...................................................................................................................... 357  Describing the JSP Life-Cycle................................................................................................................................ 358  The Page Translation Stage.......................................................................................................................... 358  The Compilation Stage ................................................................................................................................. 360  The Loading & Initialization Stage ............................................................................................................. 360  The Request Handling Stage........................................................................................................................ 361  The Destroying Stage.................................................................................................................................... 361  Creating Simple JSP Pages..................................................................................................................................... 361  Summary.................................................................................................................................................................. 364  Exercise .................................................................................................................................................................... 364  Chapter 11: Working with JSP Basic Tags and Implicit Objects ................. 365 Exploring Scripting Tags ....................................................................................................................................... 366  Types of Scripting Tags ................................................................................................................................ 366  The Scriptlet Tag.................................................................................................................................. 366  The Declarative Tag............................................................................................................................. 367  The Expression Tag ............................................................................................................................. 367  Working with JSP Scripting Tags................................................................................................................ 368  Exploring Implicit Objects..................................................................................................................................... 370  Features of Implicit Objects ......................................................................................................................... 370  Types of Implicit Objects.............................................................................................................................. 370  The request Object ............................................................................................................................... 371  The response Object............................................................................................................................. 371  The out Object ...................................................................................................................................... 371  The page Object.................................................................................................................................... 371  The pageContext Object...................................................................................................................... 371  The application Object ........................................................................................................................ 371  The session Object................................................................................................................................ 371  The config Object ................................................................................................................................. 371  The exception Object ........................................................................................................................... 371  Working with Implicit Objects .................................................................................................................... 372  Exploring Directive Tags ....................................................................................................................................... 376  Types of Directive Tags................................................................................................................................ 377  The Page Directive Tag ....................................................................................................................... 377  The Include Directive.......................................................................................................................... 378 
  • 14. Table of Contents xviii The Taglib Directive ............................................................................................................................ 378  Working with JSP Directive Tags................................................................................................................ 379  Summary.................................................................................................................................................................. 382  Exercise .................................................................................................................................................................... 382  Chapter 12: Working with JavaBeans and Action Tags in JSP ................... 383 What is JavaBean?..................................................................................................................................................384  Advantages of using JavaBeans .................................................................................................................. 384  Action Tags..............................................................................................................................................................384  Describing the Include Tag .......................................................................................................................... 385  Difference Between Include Directive and Include Action............................................................ 385  Describing the Forward Tag ........................................................................................................................ 386  Describing the Param Tag............................................................................................................................ 386  name ...................................................................................................................................................... 387  value ...................................................................................................................................................... 387  Describing the useBean Tag......................................................................................................................... 390  Describing the Attributes of the <jsp:useBean> Tag....................................................................... 390  Using the <jsp:useBean> Tag Attributes .......................................................................................... 391  Generating Servlets with the <jsp:useBean> Tag ............................................................................ 392  Describing the setProperty Tag................................................................................................................... 393  name ...................................................................................................................................................... 393  property ................................................................................................................................................ 393  value ...................................................................................................................................................... 394  param .................................................................................................................................................... 394  Describing the getProperty Tag................................................................................................................... 395  The name Attribute ............................................................................................................................. 395  The property Attribute........................................................................................................................ 395  Plugin.............................................................................................................................................................. 395  Params ............................................................................................................................................................ 396  Fallback........................................................................................................................................................... 396  Attribute ......................................................................................................................................................... 396  Body................................................................................................................................................................ 397  Element........................................................................................................................................................... 397  Text.................................................................................................................................................................. 398  Declaring a Bean in a JSP.......................................................................................................................................398  Creating a Bean.............................................................................................................................................. 398  Declaring the Bean in a JSP.......................................................................................................................... 399  Accessing the Bean Properties..................................................................................................................... 399  Generating Dynamic Content within a JSP................................................................................................ 400  Deploying and Running Application ......................................................................................................... 401 
  • 15. Table of Contents xix Summary..................................................................................................................................................................403  Exercise ....................................................................................................................................................................404  Chapter 13: Enhancing the JSP Tags Support .............................................. 405 Custom Tags............................................................................................................................................................406  Need of Custom Tags ................................................................................................................................... 406  Elements of Custom Tags............................................................................................................................. 407  Tag Library Descriptor........................................................................................................................ 407  Tag Handler.......................................................................................................................................... 408  The Tag Extension API...........................................................................................................................................410  Empty Tags..............................................................................................................................................................411  Empty Tag Handler Life Cycle.................................................................................................................... 412  Using Empty Tags......................................................................................................................................... 412  Body Content Tag Interface...................................................................................................................................420  Body Tag Handler Life Cycle ...................................................................................................................... 420  Using BodyContent Tag .............................................................................................................................. 421  Iteration tag Interface.............................................................................................................................................429  Iteration Tag Handler Life Cycle................................................................................................................. 429  Simple Tags .............................................................................................................................................................433  Life Cycle of Simple Tag Handlers ............................................................................................................. 433  Differences between Simple Tag and Classic Tag Handlers ................................................................... 435  The TryCatchFinally Interface ..............................................................................................................................435  Summary..................................................................................................................................................................436  Exercise ....................................................................................................................................................................436  Chapter 14: Understanding JSP Expression Language ............................... 437 Basic Syntax of using EL........................................................................................................................................438  Types of EL Expressions............................................................................................................................... 438  Immediate and Deferred Expressions............................................................................................... 439  Value Expressions................................................................................................................................ 439  Method Expressions............................................................................................................................ 440  Tag Attribute Types...................................................................................................................................... 440  Resolving EL Expressions ............................................................................................................................ 441  Describing the EL Resolver Classes................................................................................................... 441  EL Operators.................................................................................................................................................. 443  Types of EL Operators ........................................................................................................................ 443  An Example of Using EL Operators.................................................................................................. 444  Implicit EL Objects........................................................................................................................................ 445  Example 1 of Using Implicit EL Objects ........................................................................................... 447  Example 2 of Using Implicit EL Objects ........................................................................................... 449 
  • 16. Table of Contents xx Introducing Functions with EL.............................................................................................................................451  Using EL Functions ................................................................................................................................................451  Summary..................................................................................................................................................................453  Exercise ....................................................................................................................................................................453  Chapter 15: Implementing Internationalization ............................................. 455 Introducing Internationalization ..........................................................................................................................456  Java and Internationalization................................................................................................................................456  Describing the Locale Class ......................................................................................................................... 456  Parameters of the Locale Object......................................................................................................... 457  Using the Locale Class ........................................................................................................................ 457  Describing the ResourceBundle Class ........................................................................................................ 458  The PropertyResourceBundle Class.................................................................................................. 459  The ListResourceBundle Class........................................................................................................... 461  Internationalizing Web Applications...................................................................................................................463  Creating the JSP Views................................................................................................................................. 464  Creating the index.html View............................................................................................................ 464  Creating the Home.jsp View .............................................................................................................. 464  Creating the I18NServlet Class.................................................................................................................... 465  Creating the Resource Bundles.................................................................................................................... 465  Configuring the Application........................................................................................................................ 466  Designing the Application Directory Structure ........................................................................................ 466  Running the Application.............................................................................................................................. 467  Summary..................................................................................................................................................................468  Exercise ....................................................................................................................................................................468  Chapter 16: Working with JSP Standard Tag Library (JSTL)....................... 469 Describing JSTL Core Tags....................................................................................................................................470  General-Purpose Tags .................................................................................................................................. 470  The <c:out> tag .................................................................................................................................... 470  The <c:set> Tag .................................................................................................................................... 472  The <c:remove> Tag............................................................................................................................ 473  The <c:catch> Tag................................................................................................................................ 473  Conditional and Looping Tags.................................................................................................................... 473  Types of Conditional and Looping Tags .......................................................................................... 473  Using Conditional and Looping Tags............................................................................................... 475  Networking Tags........................................................................................................................................... 480  The <c:import> Tag............................................................................................................................. 480  The <c:url> Tag.................................................................................................................................... 480  The <c:redirect> Tag............................................................................................................................ 481 
  • 17. Table of Contents xxi The <c:param> Tag.............................................................................................................................. 481  Describing the JSTL SQL Tags ..............................................................................................................................481  Types of JSTL SQL Tags ............................................................................................................................... 481  The <sql:query> Tag............................................................................................................................ 482  The <sql:update> Tag ......................................................................................................................... 482  The <sql:param> Tag .......................................................................................................................... 482  The <sql:dateParam> Tag................................................................................................................... 483  The <sql:setDataSource> Tag............................................................................................................. 483  The <sql:transaction> Tag .................................................................................................................. 483  Using JSTL SQL Tags.................................................................................................................................... 483  JSTL Formatting Tags.............................................................................................................................................486  Basic Formatting Tags .................................................................................................................................. 486  Types of Basic Formatting Tags......................................................................................................... 486 Using Basic JSTL Formatting Tags .................................................................................................... 488  Number Formatting Tags............................................................................................................................. 490  Types of Number Formatting Tags ................................................................................................... 490  Using Number Format Tags............................................................................................................... 491  Date Formatting Tags ................................................................................................................................... 494  Types of Date Formatting Tags.......................................................................................................... 494  Using Date Formatting Tags .............................................................................................................. 495  Time Zone Formatting Tags......................................................................................................................... 497  Types of Time Zone Formatting Tags............................................................................................... 497 Using TimeZone Formatting Tags..................................................................................................... 497  JSTL XML Tags .......................................................................................................................................................499  XML Core Tags.............................................................................................................................................. 499  The <x:parse> Tag ............................................................................................................................... 500  The <x:out> Tag................................................................................................................................... 500  The <x:set> Tag.................................................................................................................................... 500  XML Flow Control Tags............................................................................................................................... 500  The <x:if> Tag ...................................................................................................................................... 501 The <x:choose> Tag............................................................................................................................. 501 The <x:when> Tag............................................................................................................................... 501 The <x:otherwise> Tag........................................................................................................................ 501 The <x:forEach> tag ............................................................................................................................ 501  XML Transformation Tags........................................................................................................................... 502  The <x:transform> Tag........................................................................................................................ 502  The <x:param> Tag ............................................................................................................................. 502  Implementing JSTL Tags .......................................................................................................................................502  Summary..................................................................................................................................................................506  Exercise ....................................................................................................................................................................506