File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Response Headers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Response Headers" Watch "Response Headers" New topic
Author

Response Headers

Ravi Singh
Ranch Hand

Joined: Aug 02, 2004
Posts: 51
Is it possible to set response headers after a response has been committed as I am under the impression that ALL response headers must be sent before the response body is sent?

e.g.
response.setHeader("headername", "headervalue");
response.flushBuffer();
response.setHeader("headername", "headervalue");
response.flushBuffer();
Sundar Gopal
Greenhorn

Joined: Jun 20, 2003
Posts: 17
once the response is committed we can't set the header. you have used flushBuffer() which commits the response which forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.


Regards,<br />SundarGopal.<br />Scjp, Scwcd, Scbcd.
HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
I think you can set several headers at one time, don't need to set it one by one.


[url]Olnex.net[/url]
[SCJP 1.2, SCJD, SCWCD]
Ravi Singh
Ranch Hand

Joined: Aug 02, 2004
Posts: 51
Do all headers have to be sent before the response body is sent?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12268
    
    1
Do all headers have to be sent before the response body is sent?

Of course - at the TCP/IP level, the response is just a single stream of characters sent to the browser. The servlet API keeps the headers separate from the output buffer until the first buffer flush, but after that the headers have been written.
Bill


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Response Headers
 
Similar Threads
doubt in flushBuffer
logout problem
Hard problem with tomcat 4.1 and jwsdp-1.3
Midlet Download/Installation Status Codes via servlet/jsp
response.isCommitted()???