Returning A File As An Attachment From JSP
// within a JSP file to make sure that the file you are
// returning is not interpreted by the browser. You use this
// when you want to return a TXT file, JPG or other file that
// the browser might open on its own rather than offer a
// dialog to the user so it can be saved.
//
// Note: In this example I'm returning a text file so I set
// the MIME type of the response to text/plain, but you need
// to make sure it matches the type of data you are returning.
response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"test.txt\"");