After some research I found that the "content-disposition" header of the HttpServletResponse provides a lot of useful things.
A general rule of thumb to set the value of "content-disposition":
* To open the file in a browser, set it to "inline; filename=MyFile.pdf"
* To download the file, set it to "attachment; filename=MyFile.pdf"
Displaying images I always set the content disposition to the "inline" option.
The following code snippet sets the content type to csv and the content disposition of the file that is being opened in the browser to a ".csv" extension.
HttpServletResponse response = <initialize it here>
response.setContentType("text/csv");
response.addHeader("content-disposition", "attachment; filename=" + "MyFile.csv");
For more information on the HttpServletResponse class look at the API Docs.
Also, I found this cool link where it explains on
how to send a pdf file.
Some forums I came across that deal with the same subject.
Servlet file download works in firefox but not in IE
Opening MS word document in browser