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?

Alex Chaffee

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.