Do I need to flush the servlet outputstream?

后端 未结 4 479
闹比i
闹比i 2020-12-08 09:57

Do I need to \"flush\" the OutputStream from the HttpServletResponse?

I already saw from to Should I close the servlet outputstream? that I don\'t need to close it,

4条回答
  •  醉酒成梦
    2020-12-08 10:21

    To point out an insidious exception to the rule “no need to flush”: Working with IBM WebSphere Application Server and using the response Writer (rather than the OutputStream) I found that I had to flush it; otherwise a final portion of my response data was lost. I suppose that IBM's HttpServletResponse class does indeed flush the OutputStream but uses a separate buffer for the Writer and does not flush it. Other application servers seem to do this.

    So if you send your response data to the Writer it is safer to flush it. But there is no need to flush the OutputStream into the bargain.

    (I would have posted this as a comment but lack the reputation to do it.)

提交回复
热议问题