Cover of JSP 2.0 - The Complete Reference

Source Code

This document lists all the source code examples featured in the book, indicating the page number on which they are found and where in the zip file to find the code.

Click jspcr2-1-01-src.zip to download the source code zip file.

Phil Hanna - Feb 22, 2003

Note: Many examples contain references to URL's, database names, and other elements that will be unique to your system. If you get a "not found" error of some kind, look at the code and verify that you are pointing to the correct location on your system.

Chapter 03: Introduction to Servlets

PageDescriptionSource File Name
25 Kilometers per liter to miles per gallon servlet chap03/WEB-INF/src/com/jspcr/servlets/K2MServlet.java
44 Example of a non thread-safe servlet chap03/WEB-INF/src/com/jspcr/servlets/ColliderServlet.java

Chapter 04: JSP Overview

PageDescriptionSource File Name
51 Kilometers per liter to miles per gallon JSP chap04/examples/K2M.jsp

Chapter 05: JSP Syntax and Semantics

PageDescriptionSource File Name
67 A custom JSP superclass chap05/WEB-INF/src/com/jspcr/servlets/NutrientDatabaseServlet.java
67 A JSP page that uses the custom superclass chap05/examples/dbuser.jsp
76 Example of a scriptlet chap05/examples/Scriptlet.jsp
78 Example of a declaration chap05/examples/Declaration.jsp
84 Prepares an HTML table from the servlet request chap05/examples/Echo.jsp

Chapter 06: Expressions, Scriptlets, and Declarations

PageDescriptionSource File Name
95 Creating an object inside an expression chap06/examples/ShowTimeD.jsp
95 Using a scriptlet to generate an ASCII table chap06/examples/ASCII_Table.jsp
98 Shows what compiler does to scriptlet contents chap06/examples/c2f.jsp
101 Shows how servlets are concatenated chap06/examples/Retained.jsp
104 The out implicit object chap06/examples/OutDemo.jsp
110 Output with implicit out object chap06/examples/colors1.jsp
110 Output with explicit out variable chap06/examples/colors2.jsp
120 Using a declaration to define class variables chap06/examples/vardec1.jsp
120 Using a declaration to define instance variables chap06/examples/vardec2.jsp
124 Using a declaration to define a method chap06/examples/methdef1.jsp
125 Lists some system properties chap06/examples/ShowProps1.jsp
127 Same but calls a declared formatting method chap06/examples/ShowProps2.jsp

Chapter 07: Request Dispatching

PageDescriptionSource File Name
135 Simple example of include directive chap07/examples/flavors.jsp
135 HTML code included by flavors.jsp chap07/examples/flavor_list.html
137 Same example using jsp:include chap07/examples/flavors2.jsp
138 Servlet used in jsp:include example chap07/WEB-INF/src/com/jspcr/servlets/FlavorListServlet.java
141 Using jsp:include to simulate a tabbed dialog chap07/examples/ShowRequest.jsp
141 Subpage included by ShowRequest.jsp chap07/examples/ShowParameters.jsp
141 Subpage included by ShowRequest.jsp chap07/examples/ShowServletRequestMethodValues.jsp
141 Subpage included by ShowRequest.jsp chap07/examples/ShowHttpServletRequestMethodValues.jsp
146 Subpage included by ShowRequest.jsp chap07/examples/ShowRequestHeaders.jsp
147 Using parameters with jsp:include chap07/examples/params/Earth.jsp
147 Page included by Earth.jsp chap07/examples/params/ShowDiameter.jsp
149 How to retrieve the original URI in an included page chap07/examples/ShowPath1.jsp
149 Page included by ShowPath1.jsp chap07/examples/ShowPath2.jsp
153 A non-visual JSP that forwards results to another chap07/examples/forward/GetFoodGroups.jsp
153 A data structure used by GetFoodGroups.jsp chap07/WEB-INF/src/com/jspcr/forward/FoodGroup.java
154 Renders the output of GetFoodGroups.jsp chap07/examples/forward/ShowFoodGroups.jsp

Chapter 08: Session and Thread Management

PageDescriptionSource File Name
164 Number guess guesser starting page chap08/examples/hidden/Start.jsp
165 Number guess guesser guess display page chap08/examples/hidden/NextGuess.jsp
167 Non-visual page that checks the number guess chap08/examples/hidden/CheckResults.jsp
169 JSP page that announces the win chap08/examples/hidden/IWin.jsp
170 JSP page that accuses the user of cheating chap08/examples/hidden/Cheater.jsp
172 Page counter that uses URL rewriting chap08/examples/url/Counter.jsp
175 Using persistent cookies to store preferences chap08/examples/cookies/CookieBasedWelcome.jsp
175 Logo used in CookieBasedWelcome chap08/examples/cookies/images/lyric_note.png
175 Resource bundle for CookieBasedWelcome chap08/WEB-INF/src/com/jspcr/sessions/welcome.properties
175 German resource bundle for CookieBasedWelcome chap08/WEB-INF/src/com/jspcr/sessions/welcome_de.properties
175 Spanish resource bundle for CookieBasedWelcome chap08/WEB-INF/src/com/jspcr/sessions/welcome_es.properties
175 French resource bundle for CookieBasedWelcome chap08/WEB-INF/src/com/jspcr/sessions/welcome_fr.properties
175 Italian resource bundle for CookieBasedWelcome chap08/WEB-INF/src/com/jspcr/sessions/welcome_it.properties
188 Servlet that keeps track of the state of the game chap08/WEB-INF/src/com/jspcr/sessions/GameState.java
191 Number guess guesser starting page using session API chap08/examples/hidden/sessionapi/Start.jsp
191 Number guess guesser next guess page using session API chap08/examples/hidden/sessionapi/NextGuess.jsp
193 Number guess guesser CheckResults page using session API chap08/examples/hidden/sessionapi/CheckResults.jsp
194 Number guess guesser Cheater page using session API chap08/examples/hidden/sessionapi/Cheater.jsp
195 Number guess guesser "I Win" page using session API chap08/examples/hidden/sessionapi/IWin.jsp
196 Session API based page counter chap08/examples/url/sessionapi/CookieCounter.jsp
197 Database connection that times out as a session binding listener chap08/WEB-INF/src/com/jspcr/jdbc/BoundConnection.java
200 A JSP subpage that uses BoundConnection chap08/examples/sessions/listeners/connect.jsp
201 Application that uses connect.jsp chap08/examples/sessions/listeners/ComposerSearch.jsp
206 Creating threads by subclassing java.lang.Thread chap08/examples/threads/ThreadExample1.java
208 Creating threads by implementing Runnable chap08/examples/threads/ThreadExample2.java
210 Implementing Runnable in an inner class chap08/examples/threads/ThreadExample3.java
213 Creating threads with Timer and TimerTask chap08/examples/threads/TimerExample.java
217 Unsynchronized threads with a bug chap08/examples/threads/SynchronizationTest.java
217 Support file for SynchronizationTest chap08/examples/threads/invoice.dat
225 Simulated authentication with a background worker thread chap08/examples/threads/SimulatedAuthentication.jsp

Chapter 09: Application Event Listeners

PageDescriptionSource File Name
242 Currency exchange rate cache chap09/WEB-INF/src/com/jspcr/listeners/currency/RateCache.java
245 Servlet context listener that updates rate cache while application is running chap09/WEB-INF/src/com/jspcr/listeners/currency/DownloadTimer.java
247 JSP page that uses the rate cache chap09/examples/currency/DollarToEuro.jsp
249 Session listener that keeps track of start and stop times chap09/WEB-INF/src/com/jspcr/listeners/traffic/Counter.java
253 Session attribute listener that minimizes uses of an expensive resource chap09/WEB-INF/src/com/jspcr/listeners/attributes/NewsController.java

Chapter 10: Filters

PageDescriptionSource File Name
261 Basic logging filter that writes to servlet container log chap10/WEB-INF/src/com/jspcr/filters/LoggingFilter.java
271 Generic base class for filters chap10/WEB-INF/src/com/jspcr/filters/BaseFilter.java
273 HTML form that does not invoke filtered GET chap10/examples/request/UnfilteredGetForm.html
275 Filter that transforms a GET into a POST chap10/WEB-INF/src/com/jspcr/filters/PostFilter.java
284 Response wrapper that buffers output for the next filter chap10/WEB-INF/src/com/jspcr/filters/BufferedResponseWrapper.java
287 Filter that sorts its response data lines chap10/WEB-INF/src/com/jspcr/filters/SortFilter.java
289 Filter that converts comma-separated-values into a table chap10/WEB-INF/src/com/jspcr/filters/CSVFilter.java

Chapter 11: Introduction to Custom Tags

PageDescriptionSource File Name
301 Tag library descriptor for sample tag chap11/WEB-INF/tlds/diagnostics.tld
302 Tag handler for GetWebServer tag chap11/WEB-INF/src/com/jspcr/taglibs/diag/GetWebServerTag.java
306 JSP page that uses the custom tag chap11/examples/ShowServer.jsp

Chapter 12: Expression Language

PageDescriptionSource File Name
336 Using EL arithmetic operators chap12/examples/Arithmetic.jsp
337 Using EL logical operators chap12/examples/Logical.jsp
338 Example of a user-written EL function chap12/WEB-INF/src/com/jspcr/el/Currency.java
339 TLD defining currency EL function chap12/WEB-INF/tlds/currency.tld
341 Registering the TLD in the deployment descriptor chap12/WEB-INF/web.xml

Chapter 13: The JSP Standard Tag Library (JSTL)

PageDescriptionSource File Name
346 Sample JSP page written with JSTL chap13/examples/Temperature.jsp
357 State bean for number guess guesser chap13/WEB-INF/src/com/jspcr/el/sessions/GameState.java
359 Start page using JSTL chap13/examples/core/numguess/Start.jsp
360 NextGuess page using JSTL chap13/examples/core/numguess/NextGuess.jsp
360 IWin page using JSTL chap13/examples/core/numguess/IWin.jsp
361 Cheater page using JSTL chap13/examples/core/numguess/Cheater.jsp
362 New CheckResults page using JSTL chap13/examples/core/numguess/CheckResults.jsp
368 Sample XML input document chap13/examples/XML/TheBirds.xml
369 Example using x:parse and x:out chap13/examples/XML/SongParser.jsp

Chapter 14: JSP Fragments

PageDescriptionSource File Name
388 Temperature conversion using SimpleTag interface chap14/examples/temperature/F2CJava.jsp
389 Tag handler that implements SimpleTag chap14/WEB-INF/src/com/jspcr/simpletags/F2CSimpleTag.java
391 Tag library descriptor for simple tag chap14/WEB-INF/chap14.tld
396 Temperature conversion using a tag file chap14/examples/temperature/F2CJsp.jsp
397 Tag file example chap14/WEB-INF/tags/toCelsius.tag

Chapter 15: Database Access with JDBC

PageDescriptionSource File Name
407 Simple JDBC example chap15/examples/ShowDept.jsp
423 Executing a query chap15/examples/QueryExample.jsp
425 Updating with SQL UPDATE chap15/examples/UpdateExample.jsp
428 SQL used by execute example chap15/examples/data.sql
429 Using the execute() method chap15/examples/ExecuteExample.jsp
433 Data file for BatchUpdateExample. chap15/examples/over90.csv
433 Using batch update chap15/examples/BatchUpdateExample.jsp
438 Using a prepared statement with a JNDI data source chap15/examples/PreparedStatementExample.jsp
448 Invoking stored procedures in MS Access chap15/examples/CallableStatementExample.jsp
453 Using a result set chap15/examples/IrishComposers.jsp
458 Using a scrollable result set chap15/examples/ScrollableResultSetExample.jsp
463 Helper class for metadata explorer chap15/WEB-INF/src/com/jspcr/jdbc/tools/MetaDataEvaluator.java
465 Form that invokes metadata explorer chap15/examples/MDForm.html
466 Main JSP page for metadata explorer chap15/examples/MetaDataExplorer.jsp

Chapter 16: JSP and XML

PageDescriptionSource File Name
474 Sample XML document chap16/dtd/birds.xml
478 DTD for sample XML document chap16/dtd/song.dtd
481 XML schema for sample XML document chap16/xsd/song.xsd
495 Product catalog document chap16/examples/instruments.xml
496 Java interface that represents one product chap16/WEB-INF/src/com/jspcr/xmlsamples/Product.java
497 Iterator over a list of Product objects chap16/WEB-INF/src/com/jspcr/xmlsamples/ProductList.java
497 Base class implementation of ProductList interface chap16/WEB-INF/src/com/jspcr/xmlsamples/AbstractProductList.java
499 DOM implementation of ProductList interface chap16/WEB-INF/src/com/jspcr/xmlsamples/DOMProductList.java
503 Generic JSP page to display results chap16/examples/ClemensAltman.jsp
505 DOM front-end to generic page chap16/examples/DOMSample.jsp
506 SAX implementation of ProductList interface chap16/WEB-INF/src/com/jspcr/xmlsamples/SAXProductList.java
509 SAX front-end to generic page chap16/examples/SAXSample.jsp
512 XSLT stylesheet for generating web page chap16/WEB-INF/xslt/instruments.xsl
514 Filter that applies XSLT transformation chap16/WEB-INF/src/com/jspcr/filters/XSLTFilter.java
514 Helper class used by XSLTFilter chap16/WEB-INF/src/com/jspcr/filters/BufferedResponseWrapper.java
519 Example of a JSP page in XML syntax chap16/examples/ClemensAltmanXML.jsp
519 XML syntax of the DOM front-end to generic page chap16/examples/DOMSampleXML.jsp
519 XML syntax of the DOM front-end to generic page chap16/examples/SAXSampleXML.jsp

Chapter 17: JSP Testing and Debugging

PageDescriptionSource File Name
525 Custom tag (with a bug) chap17/WEB-INF/src/TimerTag.java
525 TLD for buggy tag chap17/WEB-INF/tlds/debug.tld
526 JSP page that uses TimerTag chap17/examples/Timer.jsp
530 Debugging JSP that captures form parameters chap17/examples/Echo.jsp
532 JSP form that uses Echo for debugging chap17/examples/JobApplication.jsp
535 Simple HTTP client for debugging chap17/WEB-INF/webclient/src/com/jspcr/debug/webclient/WebClient.java
537 Mainline for WebClient chap17/WEB-INF/webclient/src/com/jspcr/debug/webclient/Main.java
541 Proxy web server (man in the middle) chap17/WEB-INF/tracer/src/com/jspcr/debug/tracer/Tracer.java
541 Logging interface used by tracer tool chap17/WEB-INF/tracer/src/com/jspcr/debug/tracer/Logger.java
544 Mainline for tracer tool chap17/WEB-INF/tracer/src/com/jspcr/debug/tracer/Main.java
547 Handles a single tracer request chap17/WEB-INF/tracer/src/com/jspcr/debug/tracer/RequestHandler.java

Chapter 18: Deploying Web Applications

PageDescriptionSource File Name
573 Sample web.xml deployment descriptor chap18/examples/web.xml

Chapter 19: Case Study: A Product Support Center

PageDescriptionSource File Name
N/A Stylesheet for support application chap19/casestudy/style.css
N/A Logo for application chap19/casestudy/images/logo.jpg
N/A Title image for application chap19/casestudy/images/lyric_note.png
N/A Deployment descriptor for case study chap19/casestudy/WEB-INF/web.xml
584 A customer entitled to product support chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/Customer.java
587 A supported product chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/Product.java
591 A customer/product pair chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/CustomerProduct.java
594 An employee chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/Employee.java
599 A software problem tracked by the system chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/Problem.java
606 An update to a reported problem chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/ProblemLog.java
609 An event in the life of a problem chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/Event.java
612 The model component of the MVC triad chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/Model.java
637 HTTP-specific subclass of Model chap19/casestudy/WEB-INF/src/com/lyricnote/support/model/WebModel.java
641 Sets the base URL for the application chap19/casestudy/SetBaseURL.jsp
641 Displays the LyricNote logo and top menu chap19/casestudy/Banner.jsp
642chap19/casestudy/ErrorPage.jsp
643 Prompts for customer search argument chap19/casestudy/Customers.jsp
645 Selection list of customer search results chap19/casestudy/CustomersList.jsp
647 Detail view of a single customer record. chap19/casestudy/Customer.jsp
649 Page included from Customer.jsp to display customer ID, name, and phone section. chap19/casestudy/CustomerInfo.jsp
649 Page included from Customer.jsp to display list of products purchased by this customer. chap19/casestudy/CustomerProductInfo.jsp
651 Page included from Customer.jsp to display list of problems reported by this customer. chap19/casestudy/CustomerProblemInfo.jsp
653 Detail view of a single problem record. chap19/casestudy/Problem.jsp
655 Included from Problem.jsp to generate the problem details and problem update section. chap19/casestudy/ProblemInfo.jsp
657 Included from Problem.jsp to display problem history. chap19/casestudy/ProblemHistory.jsp
659 Confirmation screen shown after problem update chap19/casestudy/Confirm.jsp
660 Prompts for product search argument chap19/casestudy/Products.jsp
661 Selection list of product search results chap19/casestudy/ProductsList.jsp
664 Selection list of problems for a product chap19/casestudy/ProductProblems.jsp
667 Prompts for a product ID chap19/casestudy/Problems.jsp
671 The base class for all state transitions chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/Action.java
673 The controller component of the MVC triad chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/ControllerServlet.java
676 Searches database for customers matching search argument chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/CustomersSearchAction.java
678 Gets detailed information for this customer chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/CustomersListSelectAction.java
679 Creates new problem for customer chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/CustomerNewProblemAction.java
680 Searches database for products matching argument chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/ProductsSearchAction.java
681 Stores product ID in model chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/ProductsListSelectAction.java
683 Stores problem ID in model chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/ProblemsSelectAction.java
684 Submits a problem update chap19/casestudy/WEB-INF/src/com/lyricnote/support/controller/ProblemSubmitAction.java