Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

encoded page with GZip is gone if refreshing  RSS feed

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.";
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!