Internet Explorer 9 does not use file name for inline attachments

前端 未结 1 1232
囚心锁ツ
囚心锁ツ 2020-12-10 06:24

I use this code in a Servlet which sets the file name of the inlined PDF document:

response.setContentType(\"application/pdf\");
response.setContentLength((i         


        
1条回答
  •  旧巷少年郎
    2020-12-10 07:16

    That's indeed default behaviour of IE. It does not use the filename attribute of the Content-Disposition header in any way to prepare a default filename for the Save As. Instead, it uses the last part of the request URL path info.

    I recommend rewriting your Servlet and/or the links in such way that the desired filename is supplied as part of request path info instead of as for example a request parameter.

    So, instead of

    View PDF
    

    or

    View PDF
    

    you need to use

    View PDF
    

    When mapped on an URL pattern of /pdfservlet/*, you can if necessary grab the filename part dynamically in the servlet as follows (for example, to locate the desired PDF file and/or to set the right filename in the header for the more decent webbrowsers):

    String filename = request.getPathInfo().substring(1); // foo.pdf
    

    This is by the way regardless of whether it's served inline or as an attachment.

    0 讨论(0)
提交回复
热议问题