Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setHeader() after forward()

 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I've read two conflicting descriptions of what happens if you call response.setHeader() after dispatch.forward(). One says you will get an IllegalStateException, the other that it simply has no effect (but no exception is thrown).

My own tests on Tomcat seem to indicate it has no effect (with no exception thrown). Can anyone confirm that? Is it in the spec? Or up to the vendor?

Thanks!
John
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly believe it has no effect. If the exception were defined in the specs, the API docs tend to explicitly state "If the response has already been committed, this method throws an IllegalStateException", and they don't say that for any of the header methods. I remember a brain-slip in my book on p.132 which has been mentioned in the errata (here if you haven't seen it already). The statement on p.105 about no exception being thrown is correct.

I doubt such a question would come up on the exam however. Hope that helps.
[ December 06, 2008: Message edited by: Charles Lyons ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic