GZIP Encoded JSP throwing Illegal State Exception
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Matthew_Brown
Posted On:   Monday, November 26, 2001 03:53 AM

I have an urgent need to get this answered-any help would be appreciated!!!! In order to speed up download time, I need to change my jsp output printwriter so that it sends GZIP encoded(this is adapted from Marty' Halls Core Java Servlets-but he used a servlet and I'm using a jsp). The following code works just fine,it actually works in the web browser under tomcat 3.2.1 and websphere 3.5 advanced- but an exception is thrown-Illegal State Exception: OutputStream is already being used. So when I test the page it works as needed, but the ugly exception is logged. With websphere- its alot of logging. I think   More>>

I have an urgent need to get this

answered-any help would be

appreciated!!!! In order to speed up
download time, I need to change my
jsp output printwriter so that it
sends GZIP encoded(this is adapted
from Marty' Halls Core Java
Servlets-but he used a servlet and I'm
using a jsp). The following code
works just fine,it actually works
in the web browser under tomcat
3.2.1 and websphere 3.5 advanced- but
an exception is thrown-Illegal

State Exception: OutputStream is
already being used. So when I test
the page it works as needed, but
the ugly exception is logged. With
websphere- its alot of logging. I
think the reason is that the jsp
automatically writes at least one
line with the default printwriter-
and I'm using the same printwriter.
I cannot do a servlet-which would
be the easiest way of getting
around this problem- does anyone have
an ideas as to how to make the
exception either not appear or be
handled better. Here is the code:

<%@ page
import= "java.util.zip.*,java.io.*,java.
util.*"%>

<%

Character qCh = new Character('"');

String qStr = new String(qCh.toString());

String encodings = request.getHeader("Accept-Encoding");

PrintWriter outWriter = null;

if ((encodings != null) && (encodings.indexOf("gzip") != -1)) {

OutputStream outA = response.getOutputStream();

outWriter = new PrintWriter(new GZIPOutputStream(outA), false);

response.setHeader("Content-Encoding", "gzip");
// System.out.println("ZIPPED VERSION");

} else {

//System.out.println("UN-ZIPPED VERSION");

outWriter = new PrintWriter
(response.getOutputStream(), false);

}

outWriter.println("Foo Bar");

outWriter.println("TESTTTTTTTING");

outWriter.println(" ");

outWriter.close();

%>

   <<Less

Re: GZIP Encoded JSP throwing Illegal State Exception

Posted By:   Vladimir_Zyrianov  
Posted On:   Wednesday, March 6, 2002 03:34 AM

When WebSphere is used - it uses apache as web server (in common case)


You can see mod_gzip at
http://www.remotecommunications.com/apache/mod_gzip/


It works fine for me.

About | Sitemap | Contact