java.io.IOException: 您的主机中的软件中止了一个已建立的连接。

我在下载文件的时候出现这个问题,搜索了一下网上的解决方案,梳理了一下代码发现是一行代码导致的:

       // 如果加上会出现您的主机中的软件中止了一个已建立的连接
	   //        response.reset();
        response.setContentType("multipart/form-data;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
        response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(downloadName, "UTF-8"));

        return response;

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方法的区别是,头和状态码没有清除。
response.reset() 来清除首部的空白行,这句话是网上看到的最多的一段话,如果去掉了万一有空白行也不行,但是不去掉就导出不了Excel文件,有大佬指点指点不。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值