In servlet 2.2 environments, you basically won't be able to do this. But
in servlet 2.3 environments, you can create a Filter to do the compression
for you, on output from either servlets or JSP pages.
Tomcat 4 includes a compression filter in the "examples" web app that does
exactly this. You're welcome to use it on any servlet 2.3-compatible
server.
Craig McClanahan
On Thu, 12 Jul 2001, Charlesworth, Chico wrote:
> Has anyone tried this?
>
> In the servlet you can simply do the following:
>
> PrintWriter out;
>
> boolean supportCompression = false;
> if (request instanceof HttpServletRequest) {
> Enumeration e =
> ((HttpServletRequest)request).getHeaders("Accept-Encoding");
> while (e.hasMoreElements()) {
> String name = (String)e.nextElement();
> if (name.indexOf("gzip") != -1) {
> supportCompression = true;
> }
> }
> }
>
> if (!supportCompression) {
> System.out.println("--------------------------------------> NOT
> COMPRESSING");
> out.getWriter();
> }
> else {
> System.out.println("-------------------------------------->
> COMPRESSING");
>
> if (response instanceof HttpServletResponse) {
> OutputStream out1 = response.getOutputStream();
> out = new PrintWriter(new GZIPOutputStream(out1), false));
> response.setHeader("Content-Encoding", "gzip");
> }
> }
>
> But because I'm using struts, changing the JSP page into a servlet will b
> difficult if not impossible.
> Does anyone know of another way around this?
>
> cheers,
> Chico.
>
>
> --
> The content of this e-mail is confidential, may contain privileged material
> and is intended solely for the recipient(s) named above. If you receive this
> in error, please notify Software AG immediately and delete this e-mail.
>
> Software AG (UK) Limited
> Registered in England & Wales 1310740
> Registered Office: Hudson House, Hudson Way,
> Pride Park, Derby DE24 8HS
>