res.setHeader("Content-Disposition", "attachment;filename=report.pdf");
至
res.setHeader("Content-Disposition", "inline;filename=report.pdf");
您还应该设置内容长度
FileCopyUtils很方便:
@Controllerpublic class FileController { @RequestMapping("/report") void getFile(HttpServletResponse response) throws IOException { String fileName = "report.pdf"; String path = "/path/to/" + fileName; File file = new File(path); FileInputStream inputStream = new FileInputStream(file); response.setContentType("application/pdf"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "inline;filename="" + fileName + """); FileCopyUtils.copy(inputStream, response.getOutputStream()); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)