代码之家  ›  专栏  ›  技术社区  ›  antongarakh

如何清除ServletOutputStream的内容?

  •  0
  • antongarakh  · 技术社区  · 7 年前

    我想知道如何从ServletOutputStream(或任何其他OutputStream)中删除所有内容,以防在某个点发生异常,并且我需要OutputStream为空,以便它不包括“一半数据”

    doSmthInServlet(HttpServletResponse respone, ....) {
            try {
                ServletOutPutStream outputStream = response.getOutputStream();
                //.....
                //writing to outputstream
                //exception occurred
            } catch (Exception e) {
                // and here I need to clear all the contents of outputStream
            }
        }
    
    0 回复  |  直到 7 年前
        1
  •  1
  •   Mark Thomas    7 年前

    ServletResponse.resetBuffer() 清除缓冲区。

    ServletResponse.reset()