This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes file download method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "file download method" Watch "file download method" New topic

file download method

g forte

Joined: Aug 28, 2003
Posts: 25
I have the following file download code that I am trying to create a method out of:

This works but I need to somehow create one method from this all or create a method from the 6 lines of code:

I need to be able to call this method from an onClick event so that the download dialog box is activated when the user clicks on a button.
Torsten Schippel
Ranch Hand

Joined: May 09, 2003
Posts: 62
you have to differ between client side and server side code. Your writeTheFileToStream method is only accessible on the server side (inside of your JSP). So you can't call it from the javascript onclick event.
I would recommend a servlet. Place your code in servlet and call it by URL inside of the javascript function.
g forte

Joined: Aug 28, 2003
Posts: 25
So theres no way to prevent this code from running onLoad? Basically If I have the code on my jsp the download dialog box opens as soon as the page loads(which I dont want). Is there not a way to call this method on demand within a jsp?
Don't get me started about those stupid light bulbs.
subject: file download method
Similar Threads
How to download a file from the server to the client machine?
Download file from Mysql database
download a csv file from jsp
upload file to client computer
How do I execute a file download from JSP