This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes downloading files from Server to client machine Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "downloading files from Server to client machine" Watch "downloading files from Server to client machine" New topic
Author

downloading files from Server to client machine

Yohan Shikari
Greenhorn

Joined: Apr 01, 2005
Posts: 13
Hi,

My project requires that I write code to download files from server to a client machine.

I have NO idea
If anyone has an idea, help me out

Post links or code

Thanks and regards
Yohan Shikari
Amol Fuke
Ranch Hand

Joined: Apr 08, 2005
Posts: 129
you need to give the links(href) to the user on browser.The href will contain the path of your file on the server.Since browser does not understand other than html, when it tries to access the specified file(given by your href) it will show a prompt having option for save and open.
When you click save ,file will be downloaded to the client.


"There are no mistakes, only lessons"
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If the files are within your webapp and can be reached from the browser, just provide links. If you need to provide access to files that reside somewhere else on the filesystem or network, you'll need to:
  • Set the Content-Type header
  • Set the Content-Disposition header
  • Stream the file to the client with a ServletOutputStrem


  • Look at SimpleStream on http://simple.souther.us.
    It streams files from within the app using getResourceAsStream.
    You would need to change it to use a FileReader if you want to send files that live outside of the webapp.
    [ May 04, 2005: Message edited by: Ben Souther ]

    Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
     
    I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
     
    subject: downloading files from Server to client machine
     
    Similar Threads
    File download in Struts
    File upload Applet
    FilesDownload from FTP
    Multi Files Transfer from client machines to server machines using socket communication in java
    using jsp to copg files from a directory