You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Cécile QUERAN <ce...@free.fr> on 2001/05/02 07:14:35 UTC

GZIP, JSP and servlet

Is there a way to gzip the output of a JSP ?

Based on the HTTP Accept-Encoding header field, I open a GZIPOutputStream if
supported by the client browser, and I send the response.getOutputStream in
it. This is within a servlet.

When I just write directly in the GZIPOutputStream, it works fine.

When I try to include a JSP's content (with the include method of the
RequestDispatcher), a problem arises : the first out.write in the service
method of my compiled JSP throws an IllegalStateException "OutputStream
already in use".

Apparently, this comes from the HttpResponseAdapter which has two parameters
to indicate whether "out" is a PrintWriter or an OutputStream. My initial
response.getOutputStream sets the useStream field to true while the JSP
framework tries to instantiate a PrintWriter. (the problem is at least on
Tomcat 3.1)

I know I can rewrite my JSP as a servlet, which would solve the problem, but
for maintenance purpose, I 'd rather keep a JSP (in fact, it includes many
other JSPs, leading to 81 kBytes, hence the need for compression).

Thanks in advance.

                            L. QUERAN



Re: GZIP, JSP and servlet

Posted by "John Clark L. Naldoza" <nj...@ntsp.nec.co.jp>.
Cécile QUERAN wrote:
> 
> Is there a way to gzip the output of a JSP ?
> 
> Based on the HTTP Accept-Encoding header field, I open a GZIPOutputStream if
> supported by the client browser, and I send the response.getOutputStream in
> it. This is within a servlet.
> 
> When I just write directly in the GZIPOutputStream, it works fine.
> 
> When I try to include a JSP's content (with the include method of the
> RequestDispatcher), a problem arises : the first out.write in the service
> method of my compiled JSP throws an IllegalStateException "OutputStream
> already in use".
> 
> Apparently, this comes from the HttpResponseAdapter which has two parameters
> to indicate whether "out" is a PrintWriter or an OutputStream. My initial
> response.getOutputStream sets the useStream field to true while the JSP
> framework tries to instantiate a PrintWriter. (the problem is at least on
> Tomcat 3.1)
> 
> I know I can rewrite my JSP as a servlet, which would solve the problem, but
> for maintenance purpose, I 'd rather keep a JSP (in fact, it includes many
> other JSPs, leading to 81 kBytes, hence the need for compression).
> 
> Thanks in advance.
> 
>                             L. QUERAN

Why not to call the JSP from your servlet, cache the output HTML and
include this in your stream?

-- 
     /) John Clark Naldoza y Lopez                           (\
    / )    Software Design Engineer II                       ( \
  _( (_    _  Web-Application Development                    _) )_
 (((\ \>  /_>    Cable Modem Network Management System <_\  </ /)))
 (\\\\ \_/ /         NEC Telecom Software Phils., Inc.  \ \_/ ////)
  \       /                                              \       /
   \    _/  phone: (+63 32) 233-9142 loc. 3112            \_    /
   /   /  cellphone: (+63 919) 399-4742                     \   \
  /   / email: njclark@ntsp.nec.co.jp                        \   \