Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

file name of an uploaded file in tomcat

Thread view: 
AA - 13 Jun 2006 14:43 GMT
I create a servlet in Tomcat that pass a file to the client, like this:

      // Open the file and output streams
       FileInputStream in = new FileInputStream(file);
       OutputStream out = response.getOutputStream();

       // Copy the contents of the file to the output stream
       byte[] buf = new byte[1024];
       int count = 0;
       while ((count = in.read(buf)) >= 0) {
           out.write(buf, 0, count);
       }
       in.close();
       out.close();
        }

When the client download the file and save it, the name of the file is
the name of the servlet.
The big question is: how can I show a name that I want instead of the
name of the servlet?

Thank you
Alb
Oliver Wong - 13 Jun 2006 15:14 GMT
>I create a servlet in Tomcat that pass a file to the client, like this:
>
[quoted text clipped - 16 lines]
> The big question is: how can I show a name that I want instead of the
> name of the servlet?

   Send the following HTTP headers:

Content-Disposition: attachment; filename="downloaded.pdf"

   - Oliver
Andrea Desole - 13 Jun 2006 15:17 GMT
> I create a servlet in Tomcat that pass a file to the client, like this:
>
[quoted text clipped - 16 lines]
> The big question is: how can I show a name that I want instead of the
> name of the servlet?

use the Content-Disposition header:

http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.