aspose file tools*
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
Author

encoded page with GZip is gone if refreshing

Tao Liu
Greenhorn

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
Thanks,
tao
--------------------
PS. Core Servlet book is free now at http://pdf.coreservlets.com/
The example is in Ch. 4.
Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
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();
}
}


Vikas Aggarwal

Founder @
Leads and Deals Limited

www.LeadsAndDeals.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: encoded page with GZip is gone if refreshing