Set filename of the Pdf that is streamed back to the browser

后端 未结 6 934
太阳男子
太阳男子 2021-02-06 03:01

I have a Java webapp creating a pdf and streaming it back to the browser.

 byte[] pdf = report.exportPdfToArray(user);
response.setContentType(\"application/pdf         


        
6条回答
  •  终归单人心
    2021-02-06 03:11

    MSIE will use the last part of the path info of the request URL (the part after the last /) as the default filename of the Save As action. It ignores the filename attribute of the Content-Disposition header altogether. All other browsers treat that header properly.

    You need to change the URL pattern of your PDF servlet to a path mapping. I.e. do not use /pdf with http://example.com/context/pdf, but rather use /pdf/* with http://example.com/context/pdf/report.pdf. This way MSIE will use "report.pdf" instead of "pdf" as the default filename for the Save As action.

提交回复
热议问题