Home > Store

Advanced JavaServer Pages

Register your product to gain access to bonus material or receive a coupon.

Advanced JavaServer Pages


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 2001
  • Dimensions: K
  • Pages: 512
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-030704-1
  • ISBN-13: 978-0-13-030704-0

  • Design and implement flexible, extensible, and maintainable applications with servlets and JSP technology
  • Master powerful authentication and internationalization techniques
  • Learn how to integrate industry-standard XML and XSLT with JSP technology
  • Use JSP technology-based templates to develop robust applications from modular components

Advanced JavaServer Pages delivers:

  • Web application design techniques based on JSP and servlets technology
  • Proven strategies for achieving enterprise-class robustness and scalability with JSP technology
  • Expert guidance on implementing JSP technology-based applications with reusable components

To fully exploit the power of JavaServer Pages technology in Web application development, based on J2EE technology, you need to master the sophisticated server-side techniques that David Geary presents in Advanced JavaServer Pages.

Geary tackles JavaServer Pages technology with the same exhaustive, authoritative approach that made his Graphic Java books into worldwide best sellers. He presents in-depth coverage of advanced topics including:

  • Implementing custom JSP technology tags
  • Designing scalable and extensible Web applications
  • Using authentication to build secure JSP technology-based applications
  • Internationalizing JSP technology-based applications for global environments

Advanced JavaServer Pages features detailed chapters on internationalization, authentication, JSP technology templates, design, and XML. It concludes with a comprehensive case study that ties together key topics developed in the book and demonstrates how to integrate advanced techniques based on JSP technology. This book is a must-have resource for every developer of Java technology creating server-side applications with JSP technology and servlets.



Download the code associated to this book. (zipped .jar file)

Sample Content

Online Sample Chapters

Advanced JavaServer Pages Security

Java Servlet Authentication

Downloadable Sample Chapter

Table of Contents
Chapter 4
Chapter 9

Table of Contents



1. Custom Tag Fundamentals.

Using Custom Tags-The JSP File. Defining Custom Tags-The TLD. Implementing Custom Tags-Tag Handlers. Specifying the TLD in WEB-INF/web.xml. The Tag Life Cycle. Thread Safety. Tags with Attributes. Accessing Page Information. Error Handling. The Tag Package. The Tag Interface. The TagSupport Class: Ancestors, Values, and Ids. Tags with Bodies. Conclusion.

2. Custom Tag Advanced Concepts.

Body Tag Handlers. The BodyTag Interface. The BodyTagSupport Class. Iteration. Scripting Variables. Storing Beans in Page Scope. Specifying Scripting Variable Information. Associating a Tag Handler and Scripting Variables. Using Custom Tag Ids. Body Content. Understanding How Body Content Works. Generating JavaScript. Nested Tags. Locating Ancestor Tags. Sharing Data. Conclusion.

3. HTML Forms.

Forms with Beans. Transmission of Form Data. Textfields, Text Areas, and Radio Buttons. Checkboxes and Options. Validation Client-side Validation with JavaScript. Server-side Validation with JSP. Server-side Validation with Servlets. Server-side Validation with Servlets and JSP Pages. A Form Framework. Facade Design Pattern for HTML Forms. The Framework. Selectable Elements. Validation. Custom Tags. Conclusion.

4. Templates.

Encapsulating Layout. Sections, Regions, and Templates. Optional Content. Role-based Content. Defining Regions Separately. Nesting Regions. Extending Regions. Combining Features. Region Tag Implementations. The Beans. The Tag Handlers. Conclusion.

5. Design.

Model 1. Model 2: An MVC Approach. A Model 2 Example. The Beans. The Deployment Descriptor. Successful Login Use Case. Creating a New Account. Conclusion.

6. Framework.

A Model 2 Framework. The Action Interface. The Action Factory. Action Routers. The Action Servlet. Retrofitting the Original Model 2 Example. Refining the Design. Adding Use Cases. Step #1: Implement a Password Hint Action. Step #2: Implement a Password Hint JSP. Step #3: Add Mappings to the Properties File. Step #4: Modify the Login Failed JSP Page. The Importance of Custom Tags. JSP Scripts. Conclusion.

7. Event Handling and Sensitive Form Resubmissions.

Event Handling for a Model 2 Framework. Sensitive Form Resubmissions. Trapping Form Resubmissions with a Model 2 Framework. Trapping Form Resubmissions Without a Framework. Conclusion.

8. I18n.

Unicode. Charsets. Non-Latin-based JSP Pages. Multilingual JSP Pages. Locales. Resource Bundles. List Resource Bundles. Using Constants for Resource Keys. Property Resource Bundles. Multiple Resource Bundles. A Bundle Cache. Formatting Locale-Sensitive Information. Dates and Times. Numbers, Currency, and Percents. Messages. Browser Language Preferences. Detecting Locales. Locating Resource Bundles. Custom Tags. A Message Tag. A Format Tag. Conclusion.

9. Security.

Servlet Authentication. Principals and Roles. Declarative Authentication. Portability. Types of Authentication. Basic Authentication. Digest Authentication. Form-Based Authentication. SSL and Client Certificate Authentication. Customizing Authentication. Resin. Tomcat 4.0. Web Application Security Elements. Programmatic Authentication. Conclusion.

10. Databases.

Database Creation. Data Sources. Database Custom Tags. The Query Tag. The ColumnNames Tag. The Columns Tag. The Rows Tag. The Release Tag. Connection Pooling. Using a Connection Pool. Creating a Connection Pool. Implementing a Simple Connection Pool. A More Capable Resource Pool. Prepared Statements. Transactions. Scrolling Through Result Sets. Conclusion.

11. XML.

Generating XML. Generating XML with Beans. Beans That Generate Their Own XML. Generating Beans from XML. Postprocessing XML. Parsing XML. Simple API for XML (SAX). SAX Custom Tags. Document Object Model (DOM).DOM Custom Tags. Transforming XML. Using JSP and XSLT Together. Using XSLT in a Custom Tag to Produce HTML. Using XSLT to Produce JSP at Compile Time. Using XSLT at Compile Time Vs. Runtime. Using Xpath. Conclusion.

12. A Case Study.

The Fruitstand. The Homepage. Going Shopping. The Storefront. The Shopping Cart. The Checkout. The Purchase. The Model 2 Framework. A The Model. The Views-JSP Pages and Templates. The Controllers-Servlets and Actions. Internationalization. Authentication. HTML Forms. Sensitive Form Resubmissions. SSL. XML and DOM. Conclusion.

Servlet Filters.




Shortly after the Swing volume of Graphic Java was published in March 1999, I became aware of the mass exodus from client-side Java to server-side Java. Because I make a living writing books, I took that exodus very seriously, so I began exploring server-side Java in search of a technology that would be appropriate for my next book. At first, I was enamored with XML, XSLT, and Java, and I spent a good deal of time experimenting with those technologies. But as exciting as those technologies are, it seemed to me that they were on the periphery of developing web applications, and I wanted something that was directly involved in the creation of web applications. Then I discovered servlets.

To be honest, I wasn't too excited about servlets. Were software developers really going to create user interfaces by generating HTML with print statements from the guts of some servlet? I knew of at least one software developer that was not. Since 1984, I've had the good fortune to develop software by using a number of object-oriented languages and very cool user interface toolkits. I've developed applications in Smalltalk, Eiffel, and NeXTSTEP, and it seemed to me that developing applications with HTML—especially HTML manually generated from servlets—was akin to trading in a Ferrari for a Yugo. Then I discovered JSP.

Although back in 1999 JSP was in its infancy, it was easy to see its potential. Here was a way to mix Java with HTML, which opened the door to all kinds of interesting possibilities. And in the Future Directions section of the JSP 1.0 specification, I saw something that really caught my eye: A portable tag extension mechanism is being considered for the JSP 1.1 specification. This mechanism permits the description of tags that can be used from any JSP page. Wow. With custom tags you could encapsulate Java code, which would essentially allow you to create custom components, in the form of tags, that could be used in conjunction with HTML. From then on, I knew that my next book would be about JSP.

So I started to write an introductory JSP book, and I actually wrote the first chapter of that book before I realized two things. First, there was going to be a glut of introductory JSP books, and I did not want to compete against all of those books. Second, and most important, that first chapter was boring, and I hate to read boring books, let alone write them. So, I decided to write this book instead.

What This Book Is About

As its name suggests, this book is an advanced treatment of JavaServer Pages. The central theme of this book is the design and implementation of flexible, extensible, and maintainable applications with beans, servlets, and JSP.

This book begins where most introductory JSP books leave off, by showing you how to implement JSP custom tags. The ability to create custom tags is arguably JSP's greatest strength because it allows software developers and page authors to work in parallel with few dependencies. Subsequent chapters cover HTML forms, JSP templates, Model 1 and Model 2 architectures, a simple Model 2 framework, handling events, internationalization, security, databases, and XML. This book concludes with a comprehensive case study that shows how to use the techniques discussed in this book to develop a nontrivial web application.

The Servlet and JSP APIs This Book Depends Upon

The code in this book depends upon the Servlet 2.2 and JSP 1.1 specifications. Although the Servlet 2.3 and JSP 1.2 specifications were first released in draft form in November 2000, as this book went to press they were still in a state of flux. Because servlet filters are arguably the most important addition to the Servlet 2.3 specification, that topic is covered in "Servlet Filters" on page 471; however, you should be aware that the code in that appendix is very likely to change by the time you read this.

How This Book's Code Was Tested

I tested all of the code in this book with Tomcat 3.2.1. If a code example from this book does not work correctly with Tomcat 3.2.1, such as the example in "Digest Authentication" on page 259, that fact is pointed out in the book's text.

Because Tomcat is the reference implementation for the Servlet and JSP specifications, all of the code in this book should work with any servlet container that conforms to the Servlet 2.2 and JSP 1.1 (or higher) specifications. If an example from this book does not work with your servlet container, it is most likely a bug in that servlet container.

I also tested all of the code in this book against Resin 1.2, which is an excellent servlet container available from http://www.caucho.com. As a general rule, it is beneficial to test your code against more than one servlet container to ensure correctness and portability.

This Book's Audience

This book was written for Java developers with a basic understanding of servlets and JSP. For most Java developers, this should be their second book that covers servlets and JSP. If you are new to servlets and JSP, I recommend the following books for your first book on those topics:

  • Core Servlets and JSP by Marty Hall, Sun Microsystems Press
  • Java Servlet Programming by Jason Hunter, O'Reilly
  • Web Development with JavaServer Pages by Fields and Kolb, Manning

It also won't hurt to have a basic understanding of design patterns and the Unified Modeling Language (UML). This book demonstrates how to implement a number of design patterns in JSP-based web applications and uses UML class and sequence diagrams to show how classes are related and how they interact, respectively. See page 181 for a list of resources on design patterns and UML.

This book was not written for page authors. If you are a page author with no Java experience, you will be better served by one of the books listed above.

How This Book Was Written

Designing object-oriented software is very much an iterative process. You start with a few classes and build on them, all the while iterating over classes, both old and new, as you integrate them to build an ever-evolving system. In object-oriented parlance, that process is known as refactoring.

After working for 15 years as a software engineer, I tend to write books the way I write software. Each of this book's chapters started out in humble fashion. And each chapter was subsequently refactored into the final product that you hold in your hands.

You can get a glimpse into this process by looking at a JavaWorld article that I wrote about JSP templates. That article is the first cut of this book's Templates chapter, so you can see where the process started for that chapter and where it ended; both the chapter and the code that it discusses underwent much refactoring.

How To Use This Book

This book is not a novel, so I don't expect anyone to sit down and read it cover to cover. Because most readers will read chapters out of order in a random fashion, nearly every chapter in the book can stand on its own. There is one exception to that rule. Chapter 6, which discusses a simple Model 2 framework, depends on Chapter 5, which introduces the Model 2 architecture. Chapter 6 retrofits an example from Chapter 5; therefore, Chapter 5 is a prerequisite for Chapter 6.

The last chapter in this book is a comprehensive case study that employs the techniques discussed throughout this book to implement a nontrivial web application. You can read (or most likely, skim) that chapter first to get a feel for those techniques, or you can read it last to see how to integrate those techniques. Or you can do both.

This Book's Custom Tag Libraries

This book discusses the implementation of approximately 50 JSP custom tags, ranging from internationalization tags to tags that use XML's Document Object Model to parse XML. There are no legal restrictions whatsoever on those tags, so you are free to use those tags in any manner you deem appropriate. See "This Book's Code" on page xvii to see how you can download those tags.

This book's custom tags serve two purposes. First, they illustrate how you can implement your own custom tags. Second, they serve to reinforce the concepts discussed throughout this book. But those custom tags are not the focus of this book; rather, it's the concepts that those tags embody that are important. For example, if you look at the internationalization chapter, you will see that most of that chapter is dedicated to internationalizing text, numbers, dates, and currency in a JSP-based web application. The last few pages of that chapter show how to implement two custom tags that perform internationalization. But it's the internationalization concepts, and not the custom tags, that take center stage in that chapter.

This Book's Code

You can download all of the code from this book, including the book's custom tag libraries, from the following URL:



Download the book's index.


Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership