Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IllegalStateException ?

 
Timothy Stone
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Satish Ramasamy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the Servlet specification, the container would ignore any headers set after the response has been committed.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Timothy Stone
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!