The moose likes Servlets and the fly likes Is it necessary to say Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is it necessary to say "out.close()" in servlet code?" Watch "Is it necessary to say "out.close()" in servlet code?" New topic

Is it necessary to say "out.close()" in servlet code?

Tony Pacific

Joined: Aug 15, 2001
Posts: 11
Normally in servlet code, for service(), doGet(), or doPost() methods, we have:
PrintWriter out = res.getWriter();
// use out to write HTML
But is it a must to say out.close()?
What if I don't?
A WebSphere book says "the web application server automatically closes the PrintWriter when the service method exits." I wonder if that is vendor dependent, or all J2EE-compliant servers are required to do so.
Can someone let me know?
Thank you in advance!
Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200

Its is better that u use out.close(), coz not all application servers will do that for u
Don't get me started about those stupid light bulbs.
subject: Is it necessary to say "out.close()" in servlet code?
Similar Threads
setting PrintWriter out = response.getWriter(); out.print("My Servlet"); response.setContentType
javax.net.ssl.SSLException: untrusted server cert chain
Is the following servlet thread safe?
out.print in JSP