Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change file name 1

Status
Not open for further replies.

joelmac

Programmer
Jun 4, 2002
92
CA
hi there,

I'm downloading files that are stored in a database using a jsp called fileGetter.jsp. The files are of all different types and names. Right now, when a file is downloaded it will always have the fileGetter.jsp name even though the original file was called something.doc.

Is there a was that I can make it keep the original file name?


________________________
JoelMac
 
Usually, I do file retrieval through a servlet that is mapped to something like "foo/*" so that the URL can actually include the filename (e.g. This makes most browsers happy and gives the user a nice filename (even if it's one you made up that has nothing to do with the way it's really stored).

However, you can also set the filename in the HTTP header with a line like this:

response.setHeader("Content-Disposition","attachment; filename=\""+ name + "\"");

In this case, you may also want to set the content type so that browsers will automatically launch Word:

response.setContentType("application/msword");

(Or you can set it to something bogus if you want users to always get a save dialog.)
 
Two quick clarifications:

1) If you go with the servlet mapping, you can always have a search JSP/Servlet that sits out there and accepts criteria, locates the file in the DB, and then redirects to an appropriate URL with a pretty filename (which is caught by a servlet that serves it up).

2) If you go with attachments, then you'll obviously have to switch that content type based on the mime type of the actual file you're serving. Of course, that should be easy enough if you're saving meta info, or you can just skip it if you're not.
 
I'd like to stick with the second option if I can since I've already started this way and it seems simpler. I have it working great with IE, but Netscape seems to be having some trouble. Any idea why this would be?


________________________
JoelMac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top