How can I cache the results of my servlet, so the next request doesn't have to go through all the calculation / database access / other time-consuming stuff all over again?

Jason Hunter, author of the O'Reilly Servlets book, has written a nice little class called CacheHttpServlet. If your servlet subclasses CacheHttpServlet and overrides one method, the superclass takes care of caching the last response.

Note that as written, it only caches one version; if you have multiple possible pages based on request parameters, it won't be as effective. Someone should probably extend this class to handle multiple pages.

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.