报错: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{……省略……}
这个异常一般是超时等把连接关掉了,此时写socket就会出现问题
可以服务端保存成文件,返回前端的是连接地址,这样就不会有问题了