package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Servlet with long output. Used to test * the effect of the gzip compression. *
* Taken from Core Servlets and JavaServer Pages 2nd Edition * from Prentice Hall and Sun Microsystems Press, * http://www.coreservlets.com/. * © 2003 Marty Hall; may be freely used or adapted. */ public class LongServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); // Change the definition of "out" depending on whether // or not gzip is supported. PrintWriter out; if (GzipUtilities.isGzipSupported(request) && !GzipUtilities.isGzipDisabled(request)) { out = GzipUtilities.getGzipWriter(response); response.setHeader("Content-Encoding", "gzip"); } else { out = response.getWriter(); } // Once "out" has been assigned appropriately, the // rest of the page has no dependencies on the type // of writer being used. String docType = "\n"; String title = "Long Page"; out.println (docType + "\n" + "