table of contents
CSAJSP/2

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.

  • ApplesAndOranges.java. Servlet that outputs an Excel spreadsheet.
  • PrimeNumberServlet.java. 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.
  • PrimeList.java. 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.
  • Primes.java. A few utilities to generate a large random BigInteger, and find the next prime number above a given BigInteger. Used by the PrimeNumberServlet.
  • ServletUtilities.java. 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.
  • ShadowedText.java. Servlet that generates JPEG images representing a designated message with an oblique-shadowed version behind it. Uses the MessageImage class.
  • MessageImage.java. 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.
  • ImageTest.java. Standalone application to test the MessageImage class.

URLs Referenced in Chapter

More Information

Java

JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts