aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ServletOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ServletOutputStream " Watch "ServletOutputStream " New topic
Author

ServletOutputStream

deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124
ServletOutputStream.flush() and ServletOutputStream.write() will commit the response.

is this true or not?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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()


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Paulo Rezende
Ranch Hand

Joined: May 13, 2008
Posts: 33

But if I use RequestDispatcher both flush() and write() will cause a IllegalStateException, right?


SCJP, SCWCD, OCBCD
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletOutputStream