aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes PrintWriter after log() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "PrintWriter after log()" Watch "PrintWriter after log()" New topic
Author

PrintWriter after log()

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 340

Could you please look into the below code and tell me why PrintWriter object doesn't work when called after writing to log?

Niiraj Patel
Ranch Hand

Joined: Sep 17, 2011
Posts: 47
Hi Faisal,

For the output to be made correctly, PrintWriter object should be flushed and must be closed with its flush() and close() methods.

e.g.
rWriter.flush(); // Writes the remaining data to the screen
rWriter.close(); // Finishes the work

Regards,
Niraj
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 340

Hi Niraj!

Thanks so much! So, flushing and closing are must? Why it worked when rWriter was used prior to writing to log?
Niiraj Patel
Ranch Hand

Joined: Sep 17, 2011
Posts: 47

flushing and closing are must?


PrintWriter object should be flushed and must be closed.

flush() should not be necessary but it's good to know that the PrintWriter does not flush before it closes the underlying stream.


Why it worked when rWriter was used prior to writing


PrintWriter has no relation with ServletContext.log()

Regards,
Niraj
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 340

Thanks a lot! Will remember it always.
 
Don't get me started about those stupid light bulbs.
 
subject: PrintWriter after log()
 
Similar Threads
Cannot get HttpSessionBindingListener method valueBound to trigger
ServletContext AttributeListener again
Problem invoking a servlet directly from FireFox browser
ServletContextAttributeListener doesn't receive attributeRemoved() notification
ListenerTester