File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes encoded page with GZip is gone if refreshing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "encoded page with GZip is gone if refreshing" Watch "encoded page with GZip is gone if refreshing" New topic

encoded page with GZip is gone if refreshing

Tao Liu

Joined: Nov 02, 2001
Posts: 13
My question is about "EncodedPage" servlet on page 106 of Marty Hall's Core Servlet & JSP.
I can make this servlet run without problem, but
the page becomes blank if I hit the browser's "refesh" button.
This may be because of close() call, but how can I get the page back?
Browser: IE 6.0
Servlet container: Tomcat 4.0
OS: Win2k
PS. Core Servlet book is free now at
The example is in Ch. 4.
Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
I think this should not happen as I have used that program a number of times and it works fine. The program is as under which gave me no problems at all...
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
public class EncodedPage extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out;
String encodings = request.getHeader("Accept-Encoding");
String encodeFlag = request.getParameter("encoding");
String title;
if ((encodings != null) &&
(encodings.indexOf("gzip") != -1) &&
!"none".equals(encodeFlag)) {
title = "Page Encoded with GZip";
OutputStream out1 = response.getOutputStream();
out = new PrintWriter(new GZIPOutputStream(out1), false);
response.setHeader("Content-Encoding", "gzip");
} else {
title = "Unencoded Page";
out = response.getWriter();
out.println( "<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n");
String line = "Blah, blah, blah, blah, blah. " +
"Yadda, yadda, yadda, yadda.";

Vikas Aggarwal

Founder @
Leads and Deals Limited
I agree. Here's the link:
subject: encoded page with GZip is gone if refreshing
It's not a secret anymore!