wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes IllegalStateException ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "IllegalStateException ?" Watch "IllegalStateException ?" New topic
Author

IllegalStateException ?

Timothy Stone
Ranch Hand

Joined: Aug 01, 2001
Posts: 71
Why doesn't this throw a ISE? I would suspect it should. The response returns true for isCommited().

I'm studying for the SCWCD and saw this code in a project I'm familiar with and thought, "wait a minute... this response is commited. Why does it work?" I thought I would ask the forum so that I could better understand something that might trip me up on the exam.

How can the headers be set after flushing and closing the output stream without throwing the ISE?


[ February 17, 2006: Message edited by: Timothy Stone ]

Timothy Stone, MIT, SCJP
http://www.petmystone.com/
"This Satan's drink [coffee] is so delicious, we shall cheat Satan and baptize it." --Pope Clement the VIII (1592-1605)
Satish Ramasamy
Greenhorn

Joined: Feb 13, 2006
Posts: 15
As per the Servlet specification, the container would ignore any headers set after the response has been committed.


Thanks,<br />Satish<br /> <br />SCJP 1.4 - 98%
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Why aren't you setting the headers BEFORE flushing? What you are trying doesn't make sense - you are trying to set headers to something that has already been sent back to the browser.


A good workman is known by his tools.
Timothy Stone
Ranch Hand

Joined: Aug 01, 2001
Posts: 71
Why aren't you setting the headers BEFORE flushing? What you are trying doesn't make sense - you are trying to set headers to something that has already been sent back to the browser.


I never said it made sense. Satish answered my question.

I found this in production code of an open source project. I have exchanged some emails with the author of the project. He's removing the statements for the very reason Satish mentioned.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException ?
 
Similar Threads
The concept of buffering in servlets
The concept of buffering in servlets
response.sendRedirect
How to send image from Servlet to J2ME app and display it on the app?
Mockito problem testing for a boolean value