File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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?
I agree. Here's the link:
subject: file download method
It's not a secret anymore!