后端跨域问题
public void downloadAnalysisReport(HttpServletRequest request, HttpServletResponse res, String fileName) throws Exception{
final File file = ImportWordUtil.getFileByName(fileName);
InputStream inputStream = null;
OutputStream os = null;
try {
if(!file.exists()) return;
//得到文件列表信息
inputStream = new FileInputStream(file);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len =0;
while((len=inputStream.read(buffer))!=-1){
outStream.write(buffer,0,len);
}
byte[] data = outStream.toByteArray();
//res.reset();
//res.addHeader("Content-Length", ""+outStream.toByteArray().length);
res.setContentLength(data.length);
// 设置输入格式
res.setContentType("application/octet-stream;charset=UTF-8");
// 获取浏览器类型
String userAgent = request.getHeader("USER-AGENT");
// 设置响应编码
res.setCharacterEncoding(CharsetConst.UTF_8);
// 设置文件名称
res.setHeader("content-disposition", String.format("attachment;filename=%s", fileName));
os = res.getOutputStream();
os.write(data);
os.flush();
inputStream.close();
os.close();
log.info("文件下载成功:" + fileName);
} catch (Exception e) {
e.printStackTrace();
}
}
res.reset();引起跨域