Casper, don't get me started on the getWriter travesty...

If it'd been createWriter() I'd agree to close it, but the whole Http- 
part of Servlets is malnourished.

So I guess I'm still in the Let-the-container-manage-it camp

Viktor,
Development Black Ops

25 maj 2009 kl. 16.01 Casper Bang <[email protected]> skrev:

>
> Joshua Bloch taught us to use these explicit termination methods. The
> tricky things is, its unclear whether getWriter actually opens a
> stream or is simply an accessor/property to one. I admit to always
> closing it explicitly, since a second call to getWriter usually
> results in "java.lang.IllegalStateException: getWriter() has already
> been called" suggesting I was the one who opened it. Certainly I would
> expect filter chain hooks beneath to simply override close() in a
> normal decorator fashion and do their post-processing? Perhaps this is
> container specific and an ugly corner of the Servlet API.
>
> /Casper
>
> On May 25, 2:21 pm, Brian <[email protected]> wrote:
>> It seems about a 50/50 split in hello world  examples of  HttpServlet
>> out on the 'internets' as to whether or not to close the
>> ServletOutputStream or PrintWriter.  NetBeans for example will put  
>> the
>> close() call in their new Servlet wizard by default.  So does  
>> Oracle's
>> JDeveloper.  But other tutorials/examples do not close it.http:// 
>> edocs.bea.com/wls/docs70/servlet/progtasks.html
>>
>> In my particular case not closing the ServletOutputStream solved an
>> 'odd behavior' bug in an application when running on HTTPS on a
>> somewhat 'black box' production environment that was using Oracle Web
>> Cache and several other pre and post processing technologies on each
>> request.  But I have not been successful at articulating why not
>> closing the outputstream is the fix or verifying there are no other
>> consequences as a result of not closing the output stream.  99% of  
>> the
>> time it seems to matter little whether the close is there are not  
>> (e.g
>> every J2EE IDE I have tried), but in this case it did Any thoughts?
>>
>> public class HelloWorldServlet extends HttpServlet {
>>   public void service(HttpServletRequest req,
>>                       HttpServletResponse res)
>>        throws IOException
>>   {
>>     // Must set the content type first
>>     res.setContentType("text/html");
>>     // Now obtain a PrintWriter to insert HTML into
>>     PrintWriter out = res.getWriter();
>>     out.println("<html><head><title>" +
>>                 "Hello World!</title></head>");
>>     out.println("<body><h1>Hello World!</h1></body></html>");
>>     //QUESTION:  close or not close:
>>     //out.close();
>>   }
>>
>> }
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to