Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

setHeader() after forward()

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

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?

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 ]
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic