This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes file download from JSP ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "file download from JSP ?" Watch "file download from JSP ?" New topic

file download from JSP ?


Joined: Jan 26, 2000
Posts: 15
I'm trying to write a JSP that pulls a file (i.e. Ms Word doc file) from a database and pushes it to the client for download.
I tried to use:
and I can only see my web browser show binary charactes .
How do I make the browser recognize the binary chars. as a file ?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12982
I think you want to set the content type specific
for the application.
and make sure your browser has a setting for
this MIME type.
To find listings of MIME types try searching
at Yahoo. Here is one listing I found recently:

Joined: Jan 26, 2000
Posts: 15
I found the solution,
you need to setHeader();
setContentType(application/octet-stream) <--generic application
some pointers too.. don't put any HTML or text tags, this will screw up the application file binary output stream
It is sorta covered in the JavaRanch Style Guide.
subject: file download from JSP ?
It's not a secret anymore!