【发布时间】:2019-06-26 23:41:54
【问题描述】:
在 Spring Boot 应用程序中,一个链接会生成一个 pdf 文件。
百里香叶中的链接
<a th:href="@{/printings/bytesttype/compressions}" class="list-group-item list-group-item-action"><span th:text="#{compressions}">Compressions</span></a>
在控制器端
@GetMapping(value = "/printings/bytesttype/compressions")
public ResponseEntity<byte[]> getCompressionsReport() throws IOException, Exception {
return preparePdfReport(samplingFacade.getCompressionToPrint());
}
private ResponseEntity<byte[]> preparePdfReport(byte[] content) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/pdf"));
String fileName = "report.pdf";
headers.setContentDispositionFormData(fileName, fileName);
headers.setCacheControl("no-cache, must-revalidate, post-check=0, pre-check=0");
ResponseEntity<byte[]> response = new ResponseEntity<>(content, headers, HttpStatus.OK);
return response;
}
其实用户点击,一个请求就完成了。
在另一个请求完成后用扩展打开
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/http://localhost:8080/printings/bytesttype/compressions
有没有办法避免这种情况?
试过了 Chrome sends two requests when downloading a PDF (and cancels one of them)
问题依然存在
【问题讨论】:
标签: spring google-chrome chromium