servlets - Internet Explorer 9 does not use file name for inline attachments -
servlets - Internet Explorer 9 does not use file name for inline attachments -
i utilize code in servlet sets file name of inlined pdf document:
response.setcontenttype("application/pdf"); response.setcontentlength((int) file.length()); response.setheader("content-disposition", "inline; filename=\"" + file.getname() + "\"");
however not work in ie 9: "save as..." dialog shows lastly path part of url followed ".pdf" (for "/some/url/invoice" "invoice.pdf")
is known bug? there workaround?
that's indeed default behaviour of ie. not utilize filename
attribute of content-disposition
header in way prepare default filename save as. instead, uses lastly part of request url path info.
i recommend rewriting servlet and/or links in such way desired filename supplied part of request path info instead of illustration request parameter.
so, instead of
<a href="/pdfservlet">view pdf</a>
or
<a href="/pdfservlet?file=foo.pdf">view pdf</a>
you need use
<a href="/pdfservlet/foo.pdf">view pdf</a>
when mapped on url pattern of /pdfservlet/*
, can if necessary grab filename part dynamically in servlet follows (for example, locate desired pdf file and/or set right filename
in header more decent webbrowsers):
string filename = request.getpathinfo().substring(1); // foo.pdf
this way regardless of whether it's served inline or attachment.
internet-explorer servlets http-headers
Comments
Post a Comment