Hi!

You cannot set the filename in a header, but there is a trick you can try:

   * map your servlet to /fileservlet/* (according to servlet spec 2.2)
   * put a link in your page pointing to /fileservlet/foo.doc
   * in the fileservlet call request.getPathInfo() to get the filename ("foo.doc")
   * map the filename to the real filename and
   * send back the real file (e.g via requestDispatcher.forward(), if the file has
     the correct extension or via include() if it does not. If it does not you have
     to set the content type manually with
     response.setContentType(getServletContext().getMimeType(String filename)))
   * as the link pointed to /fileservlet/foo.doc, the browser will take foo.doc as
     filename.

good luck,

-hendrik

David Wall wrote:

> I have a file that I'd like to return from my web server, but the name of
> the file on the web server is not the same name I'd like it to "download" as
> (like the default name that appears in the Save As when the file download
> dialog displays).
>
> For example, the real file name may be something like
> /usr/local/apache/uploaded/u100 which was originally called something like
> foo.doc when it was uploaded.  The file was renamed in order to allow
> multiple foo.doc files to be uploaded by many people without there being any
> conflict in file names (or even multiple uploads from the same person, but
> each one is unique).
>
> I have a Java servlet that can set the content-type and then writes the u100
> file to the output stream,  but the file is called "u100" by default.  I'd
> like the user to see by default the original name (foo.doc).  I have this
> info in my database, but I'm not sure how to set the "file name" of the
> downloaded file.  Is there something in the HTTP headers or the like that I
> can set like the content-type attribute is used to say whether it's
> text/html, text/plain, application/msword, etc.?
>
> Thanks,
> David
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

--
- - - - - - - - - - - - - - - - - - - - - - - - - - -
  tagtraum industries      http://www.tagtraum.com/
  jo!                 small&smart 2.2 servletengine
  Java Server & Servlets   The web-application book
  The WebApp Framework        http://www.webapp.de/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to