Home > Store

Core Servlets and JavaServer Pages (JSP)

Core Servlets and JavaServer Pages (JSP)

Book

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

Also available in other formats.

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

About

Features

  • Full coverage of new Java 2 Enterprise Edition standards.
    • Provides students with in-depth, hands-on coverage of servlets 2.2 and JSP 1.1.

  • Interaction with enterprise databases.
    • Provides students with important advanced coverage.

  • Relevant specifications.
  • Production-quality examples.
  • In-depth guide to JSP 1.0 and 1.1.
    • Provides students with guidelines for use of servlets and JSP and discusses every standard JSP element.

  • Advanced techniques.
    • Familiarizes students with sharing beans, generating Excel spreadsheets and defining custom JSP tag libraries.

  • HTML forms.
    • Shows students how to use HTML forms for collecting data from users.

  • JDBC.
    • Shows students its use in communicating with relational databases.

  • Applets and HTTP tunneling.
    • Shows students how to use them as servlet front ends.

  • Servlet and JSP Quick Reference.
    • Provides students with a handy syntax and usage summary.

  • On-line access to source code.

Description

  • Copyright 2000
  • Dimensions: 7 X 9-1/4
  • Pages: 608
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-089340-4
  • ISBN-13: 978-0-13-089340-6

  • Practical guide to using Java for Web-enabled applications and dynamic Web sites
  • In-depth coverage of the latest J2EE standards: servlets version 2.2 and JSP 1.1
  • Hundreds of completely portable, fully documented, industrial-strength examples
  • Configuration details for Apache Tomcat, Sun's JSWDK, and the Java Web Server

Servlets and JavaServer Pages provide a powerful, efficient, portable, and secure alternative to CGI programming for developing professional e-commerce sites and other Web-enabled applications. Here's all you need to leverage the latest J2EE servlet 2.2 and JSP 1.1 standards: real-world insight, advanced techniques, industrial-strength code, and hands-on coverage of three top servlet/JSP engines, including Apache Tomcat.

  • Part I gives exhaustive coverage of servlets 2.1 and 2.2. Starts with basic syntax, the servlet life cycle, and use of form data. Moves on to leveraging HTTP 1.1, cookies, and session tracking. Advanced topics include compressed Web content, persistent connections, dynamically generated images, and shopping carts for e-commerce.
  • Part II provides an in-depth guide to JSP 1.0 and 1.1, including advice on when to use servlets, JSP, or a combination of the two. Discusses every standard JSP element, including approaches for integrating JavaBeans. Advanced techniques include sharing beans, generating Excel spreadsheets, and defining custom JSP tag libraries.
  • Part III covers key supporting technologies: HTML forms, JDBC and database connection pooling, and the use of applets to communicate with servlets.
  • Servlet and JSP Quick Reference provides a handy syntax and usage summary.

Every Core Series book:

  • Demonstrates practical techniques used by professional developers
  • Features robust, thoroughly tested sample code and realistic examples
  • Focuses on the cutting-edge technologies you need to master today
  • Provides expert advice that will help you build superior software

Core Servlets and JavaServer Pages delivers:

  • Practical techniques for streamlining Web-enabled application development
  • Proven strategies for optimizing servlet and JSP performance
  • In-depth, hands-on coverage of the latest standards: servlets 2.2 and JSP 1.1
  • On-line access to all source code, available free for unrestricted use

Sample Content

Online Sample Chapters

Creating Custom JSP Tag Libraries

Handling Cookies from within Servlets

Using HTML Forms with Servlets

Downloadable Sample Chapter

Click here for a sample chapter for this book: 0130893404.pdf

Table of Contents

I. SERVLETS 2.1 AND 2.2.

1. Overview of Servlets and JavaServer Pages.

Servlets. The Advantages of Servlets Over "Traditional" CGI. JavaServer Pages. The Advantages of JSP. Installation and Setup.

2. First Servlets.

Basic Servlet Structure. A Simple Servlet Generating Plain Text. A Servlet That Generates HTML. Packaging Servlets. Simple HTML-Building Utilities. The Servlet Life Cycle. An Example Using Initialization Parameters. An Example Using Servlet Initialization and Page Modification Dates. Debugging Servlets. WebClient: Talking to Web Servers Interactively.

3. Handling the Client Request: Form Data.

The Role of Form Data. Reading Form Data from Servlets. Example: Reading Three Explicit Parameters. Example: Reading All Parameters. A Résumé Posting Service. Filtering Strings for HTML-Specific Characters.

4. Handling the Client Request: HTTP Request Headers.

Reading Request Headers from Servlets. Printing All Headers. HTTP 1.1 Request Headers. Sending Compressed Web Pages. Restricting Access to Web Pages.

5. Accessing the Standard CGI Variables.

Servlet Equivalent of CGI Variables. A Servlet That Shows the CGI Variables.

6. Generating the Server Response: HTTP Status Codes.

Specifying Status Codes. HTTP 1.1 Status Codes and Their Purpose. A Front End to Various Search Engines.

7. Generating the Server Response: HTTP Response Headers.

Setting Response Headers from Servlets. HTTP 1.1 Response Headers and Their Meaning. Persistent Servlet State and Auto-Reloading Pages. Using Persistent HTTP Connections. Using Servlets to Generate GIF Images.

8. Handling Cookies.

Benefits of Cookies. Some Problems with Cookies. The Servlet Cookie API. Examples of Setting and Reading Cookies. Basic Cookie Utilities. A Customized Search Engine Interface.

9. Session Tracking.

The Need for Session Tracking. The Session Tracking API. A Servlet Showing Per-Client Access Counts. An On-Line Store Using a Shopping Cart and Session Tracking.

II. JAVASERVER PAGES.

10. JSP Scripting Elements.

Scripting Elements. JSP Expressions. JSP Scriptlets. JSP Declarations. Predefined Variables.

11. The JSP page Directive: Structuring Generated Servlets.

The Import Attribute. The ContentType Attribute. The IsThreadSafe Attribute. The Session Attribute. The Buffer Attribute. The Autoflush Attribute. The Extends Attribute. The Info Attribute. The ErrorPage Attribute. The IsErrorPage Attribute. The Language Attribute. XML Syntax for Directives.

12. Including Files and Applets in JSP Documents.

Including Files at Page Translation Time. Including Files at Request Time. Including Applets for the Java Plug-In.

13. Using JavaBeans with JSP.

Basic Bean Use. Example: StringBean. Setting Bean Properties. Sharing Beans.

14. Creating Custom JSP Tag Libraries.

The Components That Make Up a Tag Library. Defining a Basic Tag. Assigning Attributes to Tags. Including the Tag Body. Optionally Including the Tag Body. Manipulating the Tag Body. Including or Manipulating the Tag Body Multiple Times. Using Nested Tags.

15. Integrating Servlets and JSP.

Forwarding Requests. Example: An On-Line Travel Agent. Including Static or Dynamic Content. Example: Showing Raw Servlet and JSP Output. Forwarding Requests From JSP Pages.

III. SUPPORTING TECHNOLOGIES.

16. Using HTML Forms.

How HTML Forms Transmit Data. The FORM Element. Text Controls. Push Buttons. Check Boxes and Radio Buttons. Combo Boxes and List Boxes. File Upload Controls. Server-Side Image Maps. Hidden Fields. Grouping Controls. Controlling Tab Order. A Debugging Web Server.

17. Using Applets as Servlet Front Ends.

Sending Data with GET and Displaying the Resultant Page. A Multisystem Search Engine Front End. Sending Data with GET and Processing the Results Directly (HTTP Tunneling). A Query Viewer That Uses Object Serialization and HTTP Tunneling. Sending Data by POST and Processing the Results Directly (HTTP Tunneling). An Applet That Sends POST Data. Bypassing the HTTP Server.

18. JDBC and Database Connection Pooling.

Basic Steps in Using JDBC. Basic JDBC Example. Some JDBC Utilities. Applying the Database Utilities. An Interactive Query Viewer. Prepared Statements (Precompiled Queries). Connection Pooling. Connection Pooling: A Case Study. Sharing Connection Pools.

Appendix: Servlet and JSP Quick Reference.

Overview of Servlets and JavaServer Pages. First Servlets. Handling the Client Request: Form Data. Handling the Client Request: HTTP Request Headers. Accessing the Standard CGI Variables. Generating the Server Response: HTTP Status Codes. Generating the Server Response: HTTP Response Headers. Handling Cookies. Session Tracking. JSP Scripting Elements. The JSP Page Directive: Structuring Generated Servlets. Including Files and Applets in JSP Documents. Using JavaBeans with JSP. Creating Custom JSP Tag Libraries. Integrating Servlets and JSP. Using HTML Forms. Using Applets As Servlet Front Ends. JDBC and Database Connection Pooling.

Index.

Preface

Preface

In early 1996, I started using the Java programming language for the majority of my software development work. I did some CGI programming and even worked a little with the early servlet versions, but for the most part I did desktop and client-side applications. Over the last couple of years, however, there has been a growing emphasis on server-side applications, so I became more serious about servlets and JavaServer Pages. In the past year, there has been a virtual stampede toward the technology among developers, server vendors, and the authors of the Java platform specifications. So much so, in fact, that the technology is rapidly becoming the standard tool for building dynamic Web sites and connecting Web front ends to databases and applications on a server.

Unfortunately, however, it was extremely difficult to find good practical advice on servlet and JSP development. I found a number of servlet books, but only a handful of them covered recent versions of the specification, advanced techniques, or reflected real-world experience. The few that did, if they covered JSP at all, hadn't caught up to JSP 1.0, let alone JSP 1.1. Since JSP is a better fit than servlets for many situations, what good was a servlet book that didn't also cover JSP? In the last couple of months, some JSP books have started coming out. But the bulk of them don't cover servlets. What good is that? Since an integral part of JavaServer Pages is the use of scripting elements to create servlet code, you can't do effective JSP development without a thorough understanding of servlets. Besides, most real-world sites don't use just one of the two technologies; they combine them both. Finally, as I discovered when I started teaching servlet and JSP development to my students in the Johns Hopkins part-time graduate program (most of whom were professional software developers), few programmers were already comfortable with HTTP 1.1, HTML forms, and JDBC, three critical supporting technologies. Telling them to get a separate book for each of these areas was hardly reasonable: that brought to five the number of books programmers needed if they were going to do serious servlet/JSP development.

So, in mid-1999, I put together a short servlet and JSP tutorial with a few dozen examples, put it on the Web, and tried out the material in a couple of my courses. The response was overwhelming. After only a few months, I was getting several thousand visitors a day to the tutorial along with a myriad of requests to expand the coverage of the material. I eventually bowed to the inevitable and started writing. This book is the result. I hope you find it useful.

Real Code for Real Programmers

This book is aimed at serious software developers. This is not a book that touts the potential of e-commerce or pontificates about how Web-enabled applications will revolutionize your business. Instead, it is a hands-on book aimed at helping programmers who are already convinced of the need for dynamic Web sites get started building them right away. In showing how to build these sites, I try to illustrate the most important approaches and warn you of the most common pitfalls. Along the way, I include plenty of working code: more than a hundred documented Java classes, for instance. I try to give detailed examples of the most important and frequently used features, summarize the lesser-used ones, and refer you to the APIs (available on-line) for a few of the rarely used ones.

Nor is this a book that skims dozens of technologies at a high level. Although I don't claim that this is a definitive reference on every technology it touches on (e.g., there are a number of books this size just on JDBC), if the book covers a topic, it does so in enough detail for you to sit down and start writing real programs. The one exception to this rule is the Java programming language itself. Although I don't assume any familiarity with server-side programming, I do expect you to be familiar with the basics of Java language development. If you're not, you will need to pick up a good tutorial like Core Java, Core Web Programming, or Thinking in Java.

A word of caution, however. Nobody becomes a great developer just by reading. You have to write some real code, too. The more, the better. In each chapter, I suggest that you start by making a simple program or a small variation of one of the examples given, then strike off on your own with a more significant project. Skim the sections you don't plan on using right away, then come back when you are ready to try them out.

If you do this, you should quickly develop the confidence to handle the real-world problems that brought you here in the first place. You should be able to decide where servlets apply well, where JSP is better, and where a combination is best. You should not only know how to generate HTML content, but you should also understand building other media types like GIF images or Excel spreadsheets. You should understand HTTP 1.1 well enough to use its capabilities to enhance the effectiveness of your pages. You should have no qualms about developing Web interfaces to your corporate databases, using either HTML forms or applets as front ends. You should be able to spin off complex behaviors into JavaBeans components or custom JSP tag libraries, then decide when to use these components directly and when to start requests with servlets that set things up for separate presentation pages. You should have fun along the way. You should get a raise.

How This Book Is Organized

This book is divided into three parts: Servlets, JavaServer Pages, and Supporting Technologies.

Part I: Servlets

Part I covers servlet development with the 2.1 and 2.2 specifications. Although version 2.2 (along with JSP 1.1) is mandated by the Java 2 Platform, Enterprise Edition (J2EE), many commercial products are still at the earlier releases, so it is important to understand the differences. Also, although servlet code is portable across a huge variety of servers and operating systems, server setup and configuration details are not standardized. So, I include specific details for Apache Tomcat, Sun's JavaServer Web Development Kit (JSWDK), and the Java Web Server. Servlet topics include:

  • When and why you would use servlets
  • Obtaining and configuring the servlet and JSP software
  • The basic structure of servlets
  • The process of compiling, installing, and invoking servlets
  • Generating HTML from servlets
  • The servlet life cycle
  • Page modification dates and browser caches
  • Servlet debugging strategies
  • Reading form data from servlets
  • Handling both GET and POST requests with a single servlet
  • An on-line resume posting service
  • Reading HTTP request headers from servlets
  • The purpose of each of the HTTP 1.1 request headers
  • Reducing download times by compressing pages
  • Restricting access with password-protected servlets
  • The servlet equivalent of each standard CGI variable
  • Using HTTP status codes
  • The meaning of each of the HTTP 1.1 status code values
  • A search engine front end
  • Setting response headers from servlets
  • The purpose of each of the HTTP 1.1 response headers
  • Common MIME types
  • A servlet that uses the Refresh header to repeatedly access ongoing computations
  • Servlets that exploit persistent (keep-alive) HTTP connections
  • Generating GIF images from servlets
  • Cookie purposes and problems
  • The Cookie API
  • Some utilities that simplify cookie handling
  • A customized search engine front end
  • The purposes of session tracking
  • The servlet session tracking API
  • Using sessions to show per-client access counts
  • An on-line store that uses session tracking, shopping carts, and pages automatically built from catalog entries

Part II: JavaServer Pages

JSP provides a convenient alternative to servlets for pages that mostly consist of fixed content. Part II covers the use of JavaServer Pages version 1.0 and 1.1. JSP topics include:

  • When and why you would use JavaServer Pages
  • How JSP pages are invoked
  • Using JSP expressions, scriptlets, and declarations
  • Predefined variables that can be used within expressions and scriptlets
  • The page directive
  • Designating which classes are imported
  • Specifying the MIME type of the page
  • Generating Excel spreadsheets
  • Controlling threading behavior
  • Participating in sessions
  • Setting the size and behavior of the output buffer
  • Designating pages to process JSP errors
  • XML-compatible syntax for directives
  • Including JSP files at the time the main page is translated into a servlet
  • Including HTML or plain text files at the time the client requests the page
  • Including applets that use the Java Plug-In
  • Using JavaBeans with JSP
  • Creating and accessing beans
  • Setting bean properties explicitly
  • Associating bean properties with input parameters
  • Automatic conversion of bean property types
  • Sharing beans among multiple JSP pages and servlets
  • Creating JSP tag libraries
  • Tag handler classes
  • Tag library descriptor files
  • The JSP taglib directive
  • Simple tags
  • Tags that use attributes
  • Tags that use the body content between their start and end tags
  • Tags that modify their body content
  • Looping tags
  • Nested tags
  • Integrating servlets and JSP
  • Forwarding requests from servlets to static and dynamic resources
  • Using servlets to set up beans for use by JSP pages
  • An on-line travel agency combining servlets and JSP
  • Including JSP output in servlets
  • Forwarding requests from JSP pages

Part III: Supporting Technologies

Part III covers three topics that are commonly used in conjunction with servlets and JSP: HTML forms, applets talking to servlets, and JDBC. Topics include:

  • Sending data from forms
  • Text controls
  • Push buttons
  • Check boxes and radio buttons
  • Combo boxes and list boxes
  • File upload controls
  • Server-side image maps
  • Hidden fields
  • Grouping controls
  • Tab ordering
  • A Web server for debugging forms
  • Sending GET data from an applet and having the browser display the results
  • Having applets send GET data and process the results themselves (HTTP tunneling)
  • Using object serialization to exchange high-level data structures between applets and servlets
  • Having applets send POST data and process the results themselves
  • Applets bypassing the HTTP server altogether

About the Web Site

The book has a companion Web site at http://www.coreservlets.com/. This free site includes:

  • Documented source code for all examples shown in the book; this code can be downloaded for unrestricted use
  • On-line API (in Javadoc format) for all classes developed in the book
  • Up-to-date download sites for servlet and JSP software
  • Links to all URLs mentioned in the text of the book
  • Information on book discounts
  • Reports on servlet and JSP short courses
  • Book additions, updates, and news

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership