users@glassfish.java.net

Re: servlet: try ... finally {out.close();} <-bad idea?

From: Mark Mielke <mark_at_mark.mielke.cc>
Date: Sun, 30 May 2010 14:15:40 -0400

I've been reading this thread in interest.

The general consensus seems to be "use a framework - do not try and use
the PrintWriter yourself."

However, I don't think this answers the question. It avoids the question
entirely.

There are times when using the PrintWriter yourself makes sense. Let's
treat the question of when to extend the Servlet interface and use the
PrintWriter directly as a separate question from what the correct way to
use the PrintWriter is when an exception is encountered.

JSP/JSF and Jersey were all mentioned. What do *they* do?

There is always the possibility of an exception being raised. The "try
... finally { out.close(); }" seems like a good idea, but if it isn't -
what is the alternative? What does JSP/JSF and/or Jersey do when they
implement the Servlet interface and they encounter an exception after
having written out the HTTP header, but before closing the connection?

Thanks,
mark

-- 
Mark Mielke<mark_at_mielke.cc>