Reputation: 115
This is the code snippet I am trying to run. It is working fine locally, but if I try to run it in a unix server, the name of the down loaded file is displayed as the url mapped to the servlet in the web.xml
instead of Report.xls
. Please help me…
response.reset();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=Report.xls;");
Upvotes: 2
Views: 2843
Reputation: 1108702
This is a known IE issue. It indeed completely ignores the filename in the Content-Disposition
header and uses the last part of the URL pathinfo as default filename in the Save As dialogue. You should add the filename of the download file as part of the pathinfo. E.g http://example.com/context/reportservlet/report.xls where the servlet is mapped on an url-pattern
of /reportservlet/*
(note the trailing /*
) in web.xml
.
If you want to get the specified filename in the servlet so that you can do one and other more dynamically, then you can use HttpServletRequest#getPathInfo()
for this.
String filename = request.getPathInfo().substring(1);
// Substring gets rid of leading `/`.
Upvotes: 1