It has to be the servlet's responsibility; otherwise it would not
be possible to write servlets that support HTTP keep-alive (where
the connection is held open to avoid the overhead of establishing
a new connection.)

You can also call flush() to write the data without closing the
stream.

In this case, you might also want to use WebMacro or some other
template system--mixing your HTNL into your application is going
to cause trouble down the line.

See:

   http://webmacro.org

for an alternative, anf the article here:

   http://webmacro.org/Servlet.html

for the reasons why you want to keep HTML out of your code (and
other general ideas about servlet design.)

Justin


Quoting Bob Withers ([EMAIL PROTECTED]):
> This brings up a question I've had for some time.  Whose resposibility is
> it to close the output stream?  It would seem reasonable to me that the
> servlet engine should do this but it doesn't seem to hurt anything for the
> servlet to do this (on the few engines I've tried).  Does the spec mention
> this?  Would it cause a problem for any servlet engine if the servlet
> closed this?
>
> If this isn't mentioned in the spec maybe it should be.
>
> Comments and/or suggestions?
>
> Bob
>
> At 11:44 AM 5/6/99 -0500, you wrote:
> >Try adding out.close(); at the end of the servlet. If you don't close the
> >stream, sometimes the buffer doesn't get written to the browser.
> >
> >At 10:08 AM 6/05/99 -0500, you wrote:
> >
> >>     public class Home extends HttpServlet {
> >>        public void doGet(HttpServletRequest req, HttpServletResponse res)
> >>     throws ServletException, IOException {
> >>           res.setContentType("text/html");
> >>           PrintWriter out = res.getWriter();
> >>           out.println("<HTML>");
> >>           out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
> >>           out.println("<BODY>");
> >>           out.println("<BIG>Hello World</BIG>");
> >>           out.println("</BODY></HTML>");
> >             out.close(); <------ NEW LINE
> >>        }
> >>     }
> >
> >___________________________________________________________________________
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> >of the message "signoff SERVLET-INTEREST".
> >
> >Archives: http://archives.java.sun.com/archives/servlet-interest.html
> >Resources: http://java.sun.com/products/servlet/external-resources.html
> >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
> >
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to