I created a servlet with a method for file download . I correctly set the response headers and write the file contents to servletoutputstream ,it works fine for normal files of any other format other than any image format .However for image files they are displayed on the page instead of showing a save as dialog box. Can anyone shed light onto this.The method is briefed as given below.
ServletOutputStream oStream = response.getOutputStream();
File uFile= new File(filePath);
FileInputStream fis = new FileInputStream(uFile);
int c=-1;
while ((c = fis.read()) != -1){
oStream.write(c);
}
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition", "attachment; filename=\""+getFileName(filePath)+"\"");
response.setContentType(new MimetypesFileTypeMap().getContentType(filePath));
response.setContentLength((int)uFile.length());
oStream.flush();
oStream.close();
fis.close();