Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

encoded page with GZip is gone if refreshing

 
Tao Liu
Greenhorn
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
Thanks,
tao
--------------------
PS. Core Servlet book is free now at http://pdf.coreservlets.com/
The example is in Ch. 4.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!,
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 java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.zip.*;
public class EncodedPage extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");

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.";
out.println(""+line+"</BODY></HTML>");
out.close();
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic