Web tier: servlets, JSP, Web frameworks: Using GZIPOutputStream To Compress HTML

  1. Using GZIPOutputStream To Compress HTML (4 messages)

    Hi All
      Thanks for taking time to look at my thread. I am trying to compress the HTML sent to the browser using the GZIPOutputStream class. Here is my JSP:

    <%@ page import="com.picsoft.html.*,



    response.setHeader("Content-Encoding", "gzip");

    GZIPOutputStream gzipStream = new GZIPOutputStream(response.getOutputStream());


    <% gzipStream.write("Hello".getBytes()); %>

    <% gzipStream.close(); %>


       When I view the page on IE 6, it shows a blank page. When i remove the line

     "response.setHeader("Content-Encoding", "gzip");"

      it shows the "Hello" string in a encoded way. What might be wrong? I am using weblogic as web server.

  2. Using GZIPOutputStream To Compress HTML[ Go to top ]

    Are you trying to compress the entire HTML or just this string ? I think you should servlet for this. write just to the GZIPOutputStream and not to the response.getOutputSteram()

  3. Using GZIPOutputStream To Compress HTML[ Go to top ]

    Thanks for the response David. Unfortunately our application uses JSPs and no servlets. So is there a way to compress the whole stream(not just a string) in JSP??

  4. Using GZIPOutputStream To Compress HTML[ Go to top ]

    IMHO the best solution to compress the response is to use a filter servlet. You have to assign this filter in the deployment descriptor (web.xml) of your web application.

    The interface for the filter can be found at:
    Filter Interface
  5. HTTP compression, gzip[ Go to top ]

    If you have Apache, take a look at



    See also: