In my project i need to download the file to the client machine from my server, Below is the code, its downloading the file but saving the file in the server itself. I want it to save in the client machine. Pls help me out guys. Im not getting where im going wrong.
JSP pages run on the server. Whatever code you put in there will not be able to access the client (unless the client hard drive is specifically mapped and made available to the server, but that is not the case in general).
Can't you put a link to the file on the HTML page you're generating, so that the user can click on it, and save the file wherever she wants on the local machine?
Javaranch tip: If you are going to post more than a line or two of your code, wrap the code in UBB Code tags. Doing so will preserve your indenting, making your code much easier to read. Making it easier to read makes it more likely that people will actually read it which makes it more likely that you will get help.
Thnx for the tip. I will try to follow from now can. can any one giv me sample code whoch file save the file from server to the client machine.
Joined: Jul 06, 2005
You can't save it directly on the client machine. The best you can do is send it to the client in a way that will put up a dialog box prompting them to save it.
They then get to choose where to save the file. You have no control over that part of the process (it would be a security hole)
This sort of thing is done best through a servlet. Basically you do what you are doing here, but instead of writing to a FileOutputStream, write to a ServletOutputStream, gained by calling response.getOutputStream. The sending of the file would count as the response, so you can't show an HTML page at the end of downloading the file (1 request = 1 response)
Joined: Jul 29, 2004
But i cant do that way. The requirement is some thing like this. Im quering some values from the database and showing them in the table format in a jsp page. One of the column is download img. When i click on that I need to download the file from the server and place it on the client machine, sec task is after completion of first task that is savin gto the client machine it has to open the Microsoft Outlook and that file should as the attachment(Here user dont hav to attach the file.).
Without resorting to something like signed Applets or ActiveX controls you cannot -- repeat cannot -- write any file to the client system without going through the normal dowload process described by others in this thread. Imagine the security problems if this were not the case!
Originally posted by madhavi prasad: sec task is after completion of first task that is savin gto the client machine it has to open the Microsoft Outlook and that file should as the attachment(Here user dont hav to attach the file.).