@RequestMapping(path = "/file", method = RequestMethod.GET)
public void test(HttpServletResponse response) throws IOException {
String str ="D:/1.pdf";
FileInputStream fileInputStream= new FileInputStream(str);
response.addHeader("Content-Disposition", "attachment; filename=" + str.substring(str.lastIndexOf("/") + 1));
response.setContentType("application/pdf");
byte[] bytes = new byte[fileInputStream.available()];
int i;
if ( (i = fileInputStream.read(bytes)) > 0){
response.getOutputStream().write(bytes, 0, i);
}
}
这种方式浏览器显示的title就是 file,而不是1.pdf,请问怎么才能让它显示成自定义的标题呢?
response.addHeader("Content-Disposition", "attachment; filename=" + str.substring(str.lastIndexOf("/") + 1));
这个定义用在下载文件上的,我把attachment改成inline也显示不出来