Lately, I'm often asked which books on Java servlet and JavaServer Pages (JSP) I would recommend. In fact, even when I was at a local bookstore recently someone asked me that. This month, I'll review five books that focus completely on servlets and four others that contain strong servlet content.
The five books with servlet-only content in this review are:
- Java Servlet Programming, by Jason Hunter with William Crawford
- Developing Java Servlets, by James Goodwill
- Inside Servlets: Server-Side Programming for the Java Platform, by Dustin R. Callaway
- Java Servlets by Example, by Alan R. Williamson
- Java Servlets, Second Edition, by Karl Moss
Table 1 below provides a quick review of the main characteristics of these servlet-specific books.
|Table 1. Servlet-specific books overview|
|Java Servlet Programming||Developing Java Servlets||Inside Servlets||Java Servlets by Example||Java Servlets|
|Publisher||O'Reilly||Sams||Addison Wesley||Manning||McGraw Hill|
|CD-ROM/Source from FTP site||No / Yes||No / No||Yes / No||No / No||Yes / Yes|
|Servlets/JSP Versions covered||2.0 / 0.91||2.1* / 0.92||2.1 / No||2.1 / No||2.1 / No|
|API Reference||Yes (AD)||Yes (AD)||Yes (D)||Yes (AdE)||Yes (Ad)|
|Web Servers||JWS 1.1||JWS 1.1, JRun||JWS 1.1, JRun, ServletExec||JWS 1.1, JRun, ServletExec||JWS 1.1|
The following list explains the meaning of the last several rows in this table. The first group of rows, up to "CD-ROM/Source from FTP site," should be fairly self-explanatory.
- Servlets/JSP Versions: Indicates the latest versions of the APIs the book covers. The Servlets API versions include 1.0, 2.0, 2.1, and the latest, 2.2. The JSP API versions include 0.91 (and earlier), 0.92, 1.0, and the current 1.1 version.
- Sessions: Indicates the book's level of coverage on session management, cookies (the cookie class was added to the 2.0 API), as well as state management.
- Security: Indicates the book's level of coverage on such security topics as HTTP authentication and SSL with servlets.
- XML: Indicates the book's level of coverage on using the Extensible Markup Language (XML) with servlets.
- JDBC: Indicates the book's level of JDBC-servlet connectivity coverage, such as access and connection pooling
- Internationalization: Shows the coverage level for creating Websites that display localized output through servlets, such as date/message formatting, special character set encodings, and use of property files.
- API Reference: Shows whether or not the book includes the complete
javax.servletAPI documentation. An (A) indicates the reference is included in the appendix. A (D) indicates the reference includes long descriptions, and a (d) indicates short descriptions. An (E) indicates the use of examples within the API reference.
- Web Servers: Lists the specific Web servers given a reasonable level of coverage in the book; basically, coverage on how to add a servlet to the Web server is necessary to receive a rating higher than None.
The ranking scale for these topics is None, Poor, Average, Good, Very Good. An asterisk (*) in a field means the review of the specific book provides further details of the ranking.
In addition to the five server-specific books, I reviewed four other books that contain strong servlet content:
- Professional Java Server Programming, by Andrew Patzer et al.
- Professional Java XML Programming with Servlets and JSP, by Alexander Nakhimovsky and Tom Myers
- The Developer's Guide to the Java Web Server: Building Effective and Scalable Server-Side Applications, by Dan Woods, Larne Pekowsky, and Tom Snee
- Core Java Web Server, by Chris Taylor and Tim Kimmet
Table 2 provides a quick review of these books. The table listings are the same as in Table 1 so that the books can be compared. However, you might not want to read these books for the same purpose as those in the previous group.
|Table 2. Non-servlet-specific books overview|
|Professional Java Server Programming||Professional Java XML Programming||Developer's Guide to JWS||Core Java Web Server|
|Publisher||Wrox||Wrox||Addison Wesley||Prentice Hall|
|CD-ROM/Source from FTP site||No / Yes||No / Yes||Yes / No||Yes / No|
|Servlets/JSP Versions||2.1 / 1.0||2.1 / 1.0||2.1 / 1.0||2.1 / 1.0|
|API Reference||Yes (Ad)||Yes (A)||No||No|
|Web Servers||JRun, JWS 2.0, JServ||JSWDK, JRun||JWS 1.1||JWS 1.1|
In the rest of this article, I'll review each book individually. Beside each book's title is a star rating, which is based on the book's overall coverage of servlets. One star is equivalent to a poor rating, and the highest rating (five stars) translates to exceptional coverage of servlets. Most of the books fall in the middle somewhere, and I'll explain why in this next section. I also gave two of the books -- Professional Java XML Programming with Servlets and JSP and Java Servlets by Example -- an N/A rating because I felt it wasn't fair to compare them to other books that concentrated more on teaching servlets. However, for the subjects they do cover, I would give them both four stars.
Book 1: Java Servlet Programming (5 stars)
O'Reilly's Java Servlet Programming, by Jason Hunter, is probably the most popular programming book on Java servlets. What makes this book so good is its breadth of content. If you already know Java and wish to use it to convert your CGI programs or create new ones, this book will put you well on your way to becoming a sought-after Java servlet developer.
In the first half of the book, Hunter lays a good foundation, explaining what servlets are, why they are better than CGI scripts, and how to get started using them. You'll get a basic Hello World servlet program and an overview of the servlet life cycle. You also learn ways to retrieve information about a server, client, or request. Hunter then covers sending HTML and multimedia content responses, including compressed and multipart responses, using Jef Poskanzer's freely available GIF Encoder. (See the Resources section below for more information on the latter.)
Once you get past the basics, Hunter jumps into the more useful topics. The state-management chapter covers how to identify users and manage persistent session information across stateless HTTP requests using hidden form fields, URL rewriting, cookies, and the session-tracking API. The security chapter provides good coverage of authentication and using Secure Sockets Layer (SSL). The Java Database Connectivity (JDBC) chapter provides enough of a primer so that, after reading it you'll be able to connect and retrieve your information, as well as update it and manage transactions -- even if you don't know the JDBC API. While no JDBC 2.0 coverage is provided, you do get a decent discussion of how to pool your database connections from your servlets.
Hunter then moves beyond the specific servlet-usage capabilities into the communication options. For applet-servlet communication, he covers both direct-socket and HTTP-based (tunneling) communications. The meat of the content describes a simple chat application. Unfortunately, the interservlet communication chapter uses many capabilities of the 2.0 Servlet API that are deprecated in the 2.1 API. Once you have your servlets up and running properly, it helps if you can display localized messages to the user.
The book provides some decent discussion of internationalizing your servlets. While the character-set discussion was good, I found the resource-bundle discussion lacking, with less than a page of coverage. The book ends with some odds and ends about using servlets with RMI, debugging servlets, sending email from servlets, and tuning performance. None of these is covered in-depth, but there's enough discussion to give you an idea of how to work better with your servlets.
While he introduces JavaServer Pages (JSPs), Hunter spends only about 10 pages on the topic. The coverage is also based on the version 0.91 -- which is outdated, though still used in IBM's WebSphere. Instead of relying on JSP for HTML generation, some examples in the book use WebLogic's commercial htmlKona package for HTML generation; since it's nonstandard, some might consider this a drawback. The mention of the WebLogic library is short, but the concept of HTML generation is better left to the JSP developer (page designer), rather than the servlet programmer. You shouldn't have to recompile a servlet to change the appearance of a Webpage.
The book also includes a reusable utility library -- one thing that will probably help book sales. If you like the library and want to use it with a commercial development effort, every person on your development team must own a copy of the book. How's that for a selling concept? However, the library has gone through several revisions since the book went to print and is now freely downloadable from Hunter's Website (see Resources).
Don't expect this book to be updated for the 2.1 API. Instead, Hunter states he'll go right to the API 2.2 version. See Resources for details on where to read about the update. In addition, you can find Hunter's JavaWorld articles on the differences between the 2.0 and 2.1 APIs, as well as on the differences between the 2.1 and 2.2 APIs. (As a matter of full disclosure, I should mention that I am an author of an O'Reilly Java book.)
Book 2: Developing Java Servlets (3 stars)
The least expensive servlet-specific book is
Developing Java Servlets
by James Goodwill. In it, you'll find good servlet coverage with a unique discussion of object databases and distributed objects.
Goodwill starts the book in a way that's different from most servlet books. Besides an overview of the servlet architecture and its life cycle, the reader receives an introduction to configuring the servlet development environments -- or at least, what is supposed to be the development environment. First, the book seems confused about what version of the Java Servlet Development Kit (JSDK) it uses. While the book's cover clearly says version 2.1, the text says 2.0 is current. Second, the book doesn't explain how to set up the development environment; it just tells the reader to obtain a JSDK, then quickly moves to configuring the location in which you can deploy servlets. Since the servlet classes are not part of the standard development environment and the chapter is titled "Configuring the Development Environment," I had expected to learn how to configure my environment for servlet development.
After covering the servlet basics, Goodwill moves on to the subjects of retrieving form data and generating HTML output. Instead of using JSP for extensive HTML generation, he introduces his own HTML Object Packager to create the necessary HTML tags, which seem to require excessive object creation. While useful from a purely object-oriented perspective, I found the HTML Object Packager distracting when I tried to learn only about servlets. Also, the HTML generation should be pulled out of the servlet into a JSP file, as the servlet developer shouldn't be worried about page design. The next chapter of the book covers server-side Java and includes another (nonstandard) technology you should avoid in favor of JSP. And considering the book proclaims itself to be updated for JSDK 2.1, it seems odd that it doesn't cover
RequestDispatcher. This class was introduced with the 2.1 API to redirect requests to other resources. The book offers the obligatory chapter on servlet chaining, piping the output of one servlet into the input of another. The applet-to-servlet communication chapter on HTTP tunneling is decent, with a complete GUI-based applet example.
While trying to be different by creating a Swing-based applet to communicate with a servlet, Goodwill unfortunately gets caught with the problem of moving Swing packages (a problem also encountered by many other books). You'll have to change the code to the right package (and install the Java plugin) to get the applet going. In addition, the empty Serializable interface includes a member in its description. After I had what appeared to be a rough start, I started to like this book. Moving into the more advanced topics, you'll find a nice discussion about database connectivity. While the JDBC coverage includes no mention of database transactions, Goodwill does discuss connection pooling, as well as sharing the pool across the
ServletContext, a Servlet 2.1 API-specific capability. I was distracted only by the HTML Object Packager usage, which created pages of code to format a simple HTML table. Besides JDBC-to-servlet connectivity, Goodwill offers a look into using the
ObjectStore object database with servlets, something not often covered in servlet books. (Surprisingly, one of the JWS books -- The Developer's Guide to the Java Web Server -- does so, too; more on that in a moment.)
Extending the value of your Java applications means more than just moving to the cloud. Business...
Find out what to look for in a Java IDE and get tips for deciding which of the top three--Eclipse,...
Redis isn't your typical NoSQL data store, and that's exactly why it hits the sweet spot for certain...
Find out what to look for in a Java IDE and get tips for deciding which of the top three--Eclipse,...
Extracting class interfaces into Java interfaces can increase the reusability of your code, but only if...
Look to these clever open source tools to keep secrets out of source code, identify malicious files,...
Oracle has released a guide to help developers move from Java 8 to Java 9
Oracle VP Amit Zavery explains how the Java steward is rethinking core products for cloud computing,...