Spring 在另一个 window 中响应 OutputStream

Spring response OutputStream in another window

我有一个 Spring 生成 PDF 的 MVC 控制器

...
response.setHeader("Cache-Control", "");
response.setContentType("application/pdf");                                 
final OutputStream out = response.getOutputStream();
out.write(pdfService.generateApplicationReport(device));
out.flush();
out.close();
return null;
...

我使用提交按钮生成打印件

<button id="pdfId" class="btn btn-secondary" type="submit">Print</button>      

但我想在另一个浏览器中生成它window

据我所知,您不能将其写入新的 window 或服务器端的任何内容,您可以指示客户端打开一个 link 来加载pdf 在新的 window 中 JavaScript.

EG:

<a href='somesite.com/endpoint/your_pdf_servlet_thing' target='_blank'>

访问 link 时会在浏览器中为客户端加载 PDF。