Following java code is being used to download a requested log file throgh a web application:
protected HttpServletResponse response;
....
response.setContentType("application/octet-stream");
String filename = OrgName + ".log";
response.setHeader("Content-Disposition", "attachment; filename= " + filename);
OutputStream os = response.getOutputStream();
os.write(getFile());
os.close();
Problem comes when OrgName
contains a space like "Xyz Pvt Ltd", in this case file will be download with name "Xyz" rather than "Xyz Pvt Ltd.log".The part of name after 1st space is ignored. Please note that the file is downloaded correctly, it is only the name which is not showing up correctly. Is there anything I am doing wrong? or Is it a standard behavior?
Environment: Struts 2, Jboss 5.1.0, Mozilla Firefox 3.5.3
I think I found your problem. Just set the file name string as quoted
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
This should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With