Home > Store

Core Servlets and JavaServer Pages (JSP)

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

Core Servlets and JavaServer Pages (JSP)

Book

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

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
  • 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

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020