Export File name in servlet/jsp

Thursday, 26 April 2007, 13:49 | Category : Internet, J2EE, Java, Technology
Tags :

While giving a link for export as a file, you may also want to give it a name that should come in save-as dialog or browser. To do so, you have to just set Content-Disposition header and content type of response
e.g. for saving as an excel file, following can be used:

response.setHeader(“Content-Disposition”,”attachment; filename=”" + filename + “”");
response.setContentType(“application/vnd.ms-excel”);