zoukankan      html  css  js  c++  java
  • resetBuffer方法与reset方法的使用场景:解决生成HTML或者文件下载时的首部空白行的问题

    getResponse的getWriter()方法

    getResponse的getWriter()方法连续两次输出流到页面的时候,第二次的流会包括第一次的流,所以可以使用response.reset或者resetBuffer的方法。

    reset():
    Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.

    response.reset()的使用有一个条件受限:response的任何打开流关闭之后都不能再reset .

    resetBuffer():
    Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an

    IllegalStateException.

    可以看到resetBuffer方法与reset方法的区别是,头和状态码没有清除。

    一般用于下载文件excel操作时:
    空白行的出现原因,jsp代码编译后产生。就是有jsp生成html文件的时候,html文件内部会出现很多空白行。下载后的文件内的空白行也是这样产生的。 
    因此,需要 response.reset() 来清除首部的空白行。
  • 相关阅读:
    PHP的后期静态绑定
    php的clone 浅拷贝
    python 从文件导入分类
    Yii2 主从 数据库
    什么是 jsonp ?
    为speedphp最新版添加 仿Yii 的简易版 数据验证 支持不同场景,自定义回调
    redis入门指南-安装redis
    composer -vvv
    依赖注入
    yii2-user
  • 原文地址:https://www.cnblogs.com/bkywanly/p/9724041.html
Copyright © 2011-2022 走看看