table of contents

Source Code Archive

Core Servlets and JavaServer Pages

Second Edition

Volume 1: Core Technologies

Chapter 7: Generating the Server Response: HTTP Response Headers

Complete source code for every example from this chapter, available free for unrestricted use. Live links to all URLs cited in the chapter. More information. To view source code for other chapters in this book, mouse over the table of contents bar on the left.

Source Code from Chapter

Note: right-click or shift-click on the links to download the associated file.

  • Servlet that outputs an Excel spreadsheet.
  • Servlet that processes a request to generate n prime numbers, each with at least m digits. It performs the calculations in a low-priority background thread, returning only the results it has found so far. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. It also maintains a list of a small number of previously calculated prime lists to return immediately to anyone who supplies the same n and m as a recently completed computation. Uses the PrimeList, Primes, and ServletUtilities classes.
  • PrimeNumbers.html. Front end to the PrimeNumberServlet.
  • Creates an ArrayList of large prime numbers, usually in a low-priority background thread. Provides a few small thread-safe access methods. Used by the PrimeNumberServlet.
  • A few utilities to generate a large random BigInteger, and find the next prime number above a given BigInteger. Used by the PrimeNumberServlet.
  • Utility that provides a method to read a parameter with the specified name, convert it to an int, and return it. Return the designated default value if the parameter doesn't exist or if it is an illegal integer format. Used by the PrimeNumberServlet.
  • Servlet that generates JPEG images representing a designated message with an oblique-shadowed version behind it. Uses the MessageImage class.
  • Utilities for building images showing shadowed messages. Uses the ImageIO class and thus runs only in JDK 1.4 and later. Used by the ShadowedText servlet.
  • ShadowedText.html. Front end to the ShadowedText servlet.
  • Standalone application to test the MessageImage class.

URLs Referenced in Chapter

More Information


JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA