I am new to Spring MVC, but I am impressed with its capabilities.
I am using 3.1.0-RELEASE, and I have to show the PDF in response to the form: form submission.
Here is the (small) code I wrote in the controller:
@RequestMapping(value = "new_product", method = RequestMethod.POST, params = "print") @ResponseBody public void saveAndShowPDF(ModelMap map, ShippingRequestInfo requestInfo, HttpServletRequest request, HttpServletResponse httpServletResponse) throws IOException { saveProductChanges(map, requestInfo, request, httpServletResponse); httpServletResponse.setContentType("application/pdf"); byte[] pdfImage = productService.getPDFImage(requestInfo.getRequestId()); httpServletResponse.getOutputStream().write(pdfImage); }
This code sends the PDF [] byte back to the original window.
How can I get the PDF file in a separate window so that I can still have the original browser window to display other content? The best way would be to show the PDF using the client's PDF file viewer (Adobe Reader, FoxIt, etc.), but I would be fine if the PDF appears in a separate browser window.
EDIT: I decided to set Content-Disposition so that the browser opens a save / open window where the user can open Adobe (with the loss of the main page of the browser).
httpServletResponse.setHeader("Content-Disposition","attachment;filename=cool.pdf");
Thanks everyone!
source share