File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
Consider Paul's rocket mass heater.
 
subject: IllegalStateException ?