jQuery in Action, 2nd edition*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Writing Headers to response 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 "Writing Headers to response" Watch "Writing Headers to response" New topic
Author

Writing Headers to response

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Ranchers,

What happens when "The servlet container does not write the headers before committing the response, because in HTTP the headers must be sent before the response body."

Do we end up in an IllegalStateException???


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Any participants for the post above?
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by Jothi Shankar Kumar Sankararaj:
"The servlet container does not write the headers before committing the response, because in HTTP the headers must be sent before the response body."


Jothi,

I don't understand the statement. What I know is that if we try to write headers after the response has been commited we get an IllegalStateException. There is no way that the Container won't write the headers before (if you didn't specify any, it will write the defaults). What I think happens is that the Container will send the headers just before it sends what we wrote to the outputStream when commiting the response (e.g., flushes the buffer for the first time if there is a buffer, or if there is no buffer when the first char is sent).


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Writing Headers to response