为了账号安全,请及时绑定邮箱和手机立即绑定

javaweb下载excel表超时,报错Socket closed,怎么解决?有什么好的下载方法?

javaweb下载excel表超时,报错Socket closed,怎么解决?有什么好的下载方法?

长风秋雁 2018-07-06 14:15:09
报错:java.net.SocketException: Socket closed 代码:String filename = "xxx报表"+TimeUtil.getCurrentTime()+".xls";try {filename = new String(filename.getBytes("GBK"), "ISO-8859-1");} catch (UnsupportedEncodingException e) {logger.error("下载异常");}response.addHeader("Content-Disposition", "attachment;filename="+filename);response.setContentType("application/octet-stream");OutputStream outputStream = null;try {outputStream = response.getOutputStream();//  wb 是一个excel对象来的,已经有内容wb.write(outputStream);outputStream.flush();outputStream.close();} catch (IOException e) {downloadResult = false;logger.error("下载报表异常:",e);}finally{……省略……}
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

这个异常一般是超时等把连接关掉了,此时写socket就会出现问题

可以服务端保存成文件,返回前端的是连接地址,这样就不会有问题了


查看完整回答
反对 回复 2018-08-14
  • 1 回答
  • 0 关注
  • 927 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信