• Post Reply Bookmark Topic Watch Topic
  • New Topic

Plumbing The Mysteries of IllegalStateExceptions

 
William A White
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have a method of debugging the scenario where a JSP causes an IllegalStateException as follows: "java.lang.IllegalStateException: getOutputStream() has already been called for this response"

These are extremely frustrating as I don't know how to find any evidence of what is actually causing the underlying error.

Here is my real-life example:

I have a JSP that reads in a file, does some simple string replacements, and outputs the file again. There is a whole framework in the background that does the actual work.

I created a file in Excel and saved it as an HTM file and used that as the template - works fine.

Using the exact same page, I tried using a simple .txt file, an .RTF, and others. All failed. No exception is caught by the try-catch block surrounding the whole page. Tracing the execution shows that every statement on the JSP page is executed before that IllegalStateException interrupts the application.

I've got no idea what to try!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got no idea what to try!


Try doing this in a servlet rather than a JSP. When not using a JSP to emit view markup, the inner plumbings of the JSP mechanisms just get in the way... as you are experiencing.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might try to catch the exception and print the entire stack trace. That should point out where the un-expected attempt to get the output stream is occurring.
Bill
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to take a look at the generated servlet code for your JSP.
Anything not in the <% ... %> tags in a JSP will result in an "out.println(..)" statement being created in the generated servlet code.
This, of course, will clash with your own stream handling.

This is why, as Bear mentioned, this sort of thing is easier done from a servlet.
 
William A White
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone, I'll move it over to a servlet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!