• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

calling println method after commit

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have doubt regarding committing response. As per my knowledge response is committed either when the buffer is full or when we flush the buffer. But my doubt is regarding usage of println() method after the buffer is flushed.
Say I have a code snippet like:

PrintWriter out = response.getWriter();
out.println("This is a test");
out.flush();
out.println(response.isCommitted());
out.println("Test again");

When I try this I am not getting IllegalStateException, everything works fine. It also displays true for isCommitted() method. Should it be throwing this exception and in case not then does it imply that the output can be sent to client even after the response is committed.

-Rancy
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I try this I am not getting IllegalStateException


Why do you think you'll get one ? Nothing prevents you to continue writing to the output.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey your printing something, then flushing and then printing again. What's wrong in that. It's perfectly fine. If you are forwarding something after flushing you will get IllegalStateException

Saju
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

You will get the exception only when you forward the request after flushing the output..

It is also container dependent

Regards
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Thanks to all of you for your replies.
The reason I asked this question was: I was under the impression that once the response stream is committed any other attempt to write to it would result in an IllegalStateException, except if it is after a sendError or sendRedirect, in which case it will simply be ignored. Also any attempt to add a header or content type to the response after it is committed will also be ignored. Other than that any attempt to write to the response stream will result in an IllegalStateException. Probably I am not clear with the concept of committing the response. So far from what I have understood I think committing response means ensuring that data in the buffer has been sent to the client. If some one can explain the concept of committing the response to me I would really appreciate that.

Thanks,
-Rancy
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic