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 Struts and the fly likes File download 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 » Frameworks » Struts
Reply Bookmark "File download" Watch "File download" New topic
Author

File download

Donn Manlapas
Greenhorn

Joined: Aug 15, 2002
Posts: 4
How do I implement a file download in Struts?


SCJP, SCWCD
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4725

Put a link to the file that you want the users to download.


A good workman is known by his tools.
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi
I dont think its a good idea to place that document as a link ...becuase with that u wont be able to control the Header variables(like dispaly name of the file to be downloaded) and also u cant handle exceptions like filenotfound..........and even giving in a link makes the user to know the url(if u not using frames)
Hence i would advise u to call a servlet(action class) and there inside that redirect it to the url where the document is present .(THus url wont be visible and u can handle filenotfound exception ) and also u can set the response header variables like
response.setContentType("application/x-download");(This forces to open that windows save dialog box)
response.setHeader("Content-Disposition", "attachment; filename=" + docName);( this will cahnge the display name of the file while showing the dialog box)

Regards
Sreenath
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4725

I think they would still know the url if you're using frames - View Source.
Good suggestions, Sreenath.
 
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: File download
 
Similar Threads
xml4j.jar
Install
File move using Runtime or java.io
where to download isapi_redirect.dll?
how to execute simple swing program