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 / Tools / June 2006

Tip: Looking for answers? Try searching our database.

Tomcat - How to upload a file with the right name

Thread view: 
AA - 13 Jun 2006 14:41 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
bjoern_ - 14 Jun 2006 07:46 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?

I got the same problem some time ago, I solved it that way, that I
opened a popup and set the location.href with the file-link I want to
send.

Maybe also set the header and the content-type sould be a way..

// (HttpServletResponse)
response.setContentType( "application/pdf" );
response.addHeader("Content-Disposition", "attachment; filename="
         + fileName);

bjoern_
AA - 14 Jun 2006 12:50 GMT
Thx, it works!
Alberto

bjoern_ ha scritto:

> I got the same problem some time ago, I solved it that way, that I
> opened a popup and set the location.href with the file-link I want to
[quoted text clipped - 8 lines]
>
> bjoern_


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.