Source :
http://www.ideas2work.com/jsp-code-download.html
Code for downloading a file with a save as window with an exact file name.
Want to write a download link for allowing user to have a
Save As window popup and on clicking save as button,should have the same name as the file
Here is a sample servlet code for your use:
ServletOutputStream out = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment;filename="+fileName);
in = new FileInputStream(fileName);
int availableLength = in.available();
byte[] totalBytes = new byte[availableLength];
int byteData = in.read(totalBytes);
out.write(totalBytes);
This code works and perfectly fine.