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;");
This is a known IE issue. It indeed completely ignores the filename in the
Content-Dispositionheader 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 anurl-patternof/reportservlet/*(note the trailing/*) inweb.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.See also: