想在浏览器里直接GET目标URL,然后就把PDF在浏览器里预览出来(不用前端插件的前提下),就像这样:http://docs.spring.io/spring/...后端代码:@RequestMapping(value = "/showPDF", method = RequestMethod.GET)public ResponseEntity<byte[]> pdfDownload( HttpServletRequest httpServletRequest) throws IOException{ String path = XXX省略。。。 File file = new File(path); HttpHeaders httpHeaders = new HttpHeaders(); String fileName = file.getName(); httpHeaders.setContentDispositionFormData("attachment", java.net.URLEncoder.encode(fileName,"UTF-8")); httpHeaders.setContentType(MediaType.parseMediaType("application/pdf")); return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), httpHeaders, HttpStatus.CREATED);}然后想在前端直接GET这个URL地址:http://localhost:8080/FileUpDown/showPDF但是却成了下载文件而不是预览了。。。这是chrome的输出:**Response Headers***view sourceContent-Disposition:form-data; name="attachment"; filename="1472111731322JavaScript%E6%9D%83%E5%A8%81%E6%8C%87%E5%8D%97.pdf"Content-Length:21962427Content-Type:application/octet-stream;charset=UTF-8Date:Thu, 25 Aug 2016 08:32:56 GMTServer:Apache-Coyote/1.1*Conrent-Type明显不对,请问该如何解决?
6 回答
胡子哥哥
TA贡献1825条经验 获得超6个赞
慕码人2483693
TA贡献1860条经验 获得超9个赞
把RequestMapping那行改成试试:
@RequestMapping(value = "/showPDF", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)
添加回答
举报
0/150
提交
取消