akash kumar wrote:why should we set response.setContentType before using PrintWriter or OutputStream?
You have to tell the browser what kind of data are you sending so that it can handle it appropriately...
OCJP 6 (93%)
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
1
posted
0
Obviously you can't set response headers if the response output stream has been flushed.
Now you might think that writing is safe because the output buffer would hold some characters before flushing - that way lies very mysterious future bugs.
William Brogden wrote:Obviously you can't set response headers if the response output stream has been flushed.
Now you might think that writing is safe because the output buffer would hold some characters before flushing - that way lies very mysterious future bugs.
Bill
Does it mean the web server starts sending the results to the browser even before the doGet or doPost methods are returned?
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
1
posted
0
Does it mean the web server starts sending the results to the browser even before the doGet or doPost methods are returned?
Absolutely!
Thats why, if your application has to sent a content-length header, you have to provide your own buffering or temporary file scheme while you build the complete response.
Bill
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: why should we set response.setContentType before using PrintWriter or OutputStream?