Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Returning A File As An Attachment From JSP (See related posts)

// This is truly a snippet. It's a small piece of code you use
// 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\"");

Comments on this post

hudhaifa posts on Nov 08, 2006 at 15:47
Coooooooooooooooooooooooooolllllllllllllllllllllll

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts