• Post Reply Bookmark Topic Watch Topic
  • New Topic

Illegal State Exception with GZIP jsp-help!!!!!  RSS feed

Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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("<!--End of Custom Footer -->");
Posts: 11629
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would check to see if your code doesn't conflict with some of the other things in a JSP. Check the following:
1. The implicit object out (javax.servlet.jsp.JspWriter)
2. The @page directive contentType attribute which defaults to "text/html; charset=ISO-8859-1"

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!