Hi Andr�s,
I havent used compression myself, but info may be found in J. Hunters
servlet book on page 189. According to this, you need to set the content
header of the response to x-gzip or x-compress (not just to gzip as you
do).
Also, revise your check for the the header, it might return null in which
case your first line would fail with a NullPointerException.
Please tell me if you get it working!!
Regards
Heiko
[EMAIL PROTECTED]
Andr�s Aguiar <[EMAIL PROTECTED]> on 07-08-99 11:53:47
Please respond to "A mailing list for discussion about Sun Microsystem's
Java Servlet API Technology."
<[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Heiko Grussbach/NMG/CRP-HT)
Subject: Compressing the output of a servlet
Content-type: text/plain; charset
I'm trying to send the output of my servlet compressed to the browser,
depending on the 'Accept-Encoding' header in the HTTP request.
I've followed the HTTP1.1 spec, but it seems that I'm doing something
wrong.
This is the code I'm using:
//-----------------------------
// htmlOut is a StringBuffer that has the data to send to the browser.
if (req.getHeader("Accept-Encoding").indexOf("gzip") >{
res.setHeader("Content-Encoding", "gzip");
res.setHeader("Transfer-Encoding","chunked");
res.getOutputStream().write(new
String(Long.toHexString(htmlOut.length()).toUpperCase() +
"\r\n").getBytes());
GZIPOutputStream gzOut GZIPOutputStream(res.getOutputStream());
gzOut.write(htmlOut.toString().getBytes());
gzOut.close();
res.getOutputStream().write(new
String("\r\n0\r\n\r\n").getBytes());
res.getOutputStream().close();
}
//---------------------
If someone was able to do it, send me a clue.
Regards.
___________________________________________________________________________
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
___________________________________________________________________________
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