Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

output printed after response.flushBuffer()

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

According to p. 126 of Charles Lyon's book,
The response is committed by flushing the buffer on line 23, so , line 24 has no effect

But why the response still have "Hello world" printed on the screen?
I think the response has been committed in line 23 and nothing should be output after line 23.


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why the response still have "Hello world" printed on the screen?
I think the response has been committed in line 23 and nothing should be output after line 23.

Correct, the Response has been committed but it has not yet been closed. It will be closed at the end of the service method:
5.5 Closure of Response Object
When a response is closed, the container must immediately flush all remaining content in the response buffer to the client. The following events indicate that the servlet has satisfied the request and that the response object is to be closed:
- The termination of the service method of the servlet.
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Frits. Thanks for your reply.
But after flushBuffer() is called,
The response has not been closed after line 23.
Why the response.setHeader in line 24 does not set the header ?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the headers are the first ones to get flushed to the client. Once a response is commited you can't change the headers anymore.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic