下载pdf时 显示 为打开还是直接下载
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
Calendar cale = Calendar.getInstance();
String datetime = sdf2.format(cale.getTime());
ByteArrayOutputStream OS =makePdf(PaymentUnitAllList,exportAllList,datetime);
//保存文件到本地
OutputStream OutputStream = null;
try {
response.setContentType(" application/pdf");
response.setHeader("Content-disposition", "attachment;filename=" + datetime + ".pdf");//inline attachment
//attachment 下载 ***************
//inline 直接打开 *************
OutputStream = response.getOutputStream();
OutputStream.write(OS.toByteArray());
OutputStream.flush();
OutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
OutputStream.flush();
OutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
导出excel配置
String fileName = new String(excleName.getBytes("gb2312"), "ISO-8859-1");
response.setContentType("application/nd.ms -excel");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
OutputStream ouputStream = response.getOutputStream();
总结: //attachment 下载 *************** //inline 直接打开 *************