"Lopez, Steven A (Steve)" wrote:
> Servlet Guru's:
>
> For the sake of network performance I would like
> to compress the html in my servlet using Java's zip
> classes and then return that byte-stream back to the
> browser. Though we can successfully compress the byte
> stream we haven't been able to get the browser to
> properly understand what to do with the data; it wants
> to prompt the user to save it rather than uncompressing
> it and rendering the HTML.
>
> Any tips? We have tried 'response.setContentType("text/gzip")'
> but that doesn't work.
>
You want to leave the content type as "text/html", if that is what it is.
Instead, you want to add a separate heading to document the fact that you are
zipping it:
response.setHeader("Content-Encoding", "gzip");
You should only do this if you know for sure that the browser knows what to do
with compressed streams. The standard way to find out is to check the value of
the request header "Accept-Encoding" -- if the browser sent it -- to make sure
that "gzip" is one of the valid encodings.
This stuff is documented in the HTTP/1.1 specification that you can download
from a variety of places. I usually go to:
http://www.rfc-editor.org
and use one of the search engines. You want RFC 2616.
>
> We are fairly positive this can work because if we just
> put a static gzipped file on the webserver the browser
> will know what to do with it, but when we try to create the
> same bytestream dynamically within a serlvet it doesn't work.
> We are thinking it has something to do with the content-type
> or other header information.
>
> Any thoughts are appreciated.
>
> -Steve
>
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html