This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

ServletOutputStream

 
deepa raj
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletOutputStream.flush() and ServletOutputStream.write() will commit the response.

is this true or not?
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by deepa raj:
ServletOutputStream.flush() and ServletOutputStream.write() will commit the response.

is this true or not?


Only ServletOutputStream.flush() will commit the response and not ServletOutputStream.write(). ServletOutputStream.write() is a method which the ServletOutputStream inherits from OutputStream. It is used to write bytes to the target of the OutputStream. ServletOutputStream adds overloaded print and prinln methods to send String and other type of output to the target or destination. So you should use them and not write()
 
Paulo Marcio Brandi Rezende
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if I use RequestDispatcher both flush() and write() will cause a IllegalStateException, right?
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paulo Rezende:
But if I use RequestDispatcher both flush() and write() will cause a IllegalStateException, right?


You mean that if you forward your request after a flush or write then it will throw an IllegalStateException. Ya it's true because when you write something to the output it will be automatically flushed(depending upon the implementation of ServletOutputStream in the Servlet library of the server as ServletOutputStream is abstract).

An IllegalStateException is thrown if any content has been sent to the output stream before request dispatching.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic