You need to stream the file contents through the response output stream, using the HSSFWorkBook.write method. See the "Simple Stream" example in http://faq.javaranch.com/java/CodeBarnServlets for how to do that. And, yes, you need to set the appropriate content type.
Ping & DNS - updated with new look and Ping home screen widget
i modified my program but it does not give me the desire result
here once i export to excel the file gets saved on the server machines' D: not on my machine also i want the option that once the excel file is written i want to provide the user with an option of open save cancel . can naybody please suggest me how do i do this...
Joined: Mar 22, 2005
Instead of writing the file to disk, and then using getResourceAsStream, you should stream the workbook contents directly to the servlet output stream, using the method I mentioned earlier.
Then the browser will prompt the user what to do with the file.
how can i provide a link to file that is dynamically created, do i need to store it somewhere on the client machine .... if yes how could i store the files on client machine that are created at runtime through a servlet ., also once the file gets created at runtime i want to open the file and display its contents , can any body suggest me how do i do this.
You need to distinguish between "server side" and "client side". Those are in fact two physically separate machines with each physically an own file system. On each side the path "c:/foo/bar.ext" would point to the local file system.
Imagine that I am the client and that you are the server, how would you be able to access my local file system? I have a file at c:/documents/picture.jpg, are you able to access it? Would the server machine be? Think about it.
To send a file from the server to the client, the client need to request it and the server need to send the file with the response. In the server side you get the file contents as an InputStream and you write it to the OutputStream of the response. That's all. To pop a 'save as' dialogue, you need to set the content-disposition header to "attachment".
My main problem was to call a servlet using AJAX and then show the client open save and cancel dialogue box.... and i solved it
by invoking "../reports/BillIDPropIDExcelExport servlet i saved the excel file in a public folder and returned back the filename, now in the function(data)
you can see i am invoking another servlet called OpenFile which just take the file name and open the file from public folder. A TimeBeing Solution :idea:
Still i have a Doubt when server cannot access the client local file system.... now if i dont want to show the open save and cancel box just directly save the file on client machines local file system and when i write like this where should the FileOutputStream point to
ruquia tabassum wrote:Still i have a Doubt when server cannot access the client local file system.... now if i dont want to show the open save and cancel box just directly save the file on client machines local file system
Cannot be done. Imagine the security ramifications if it could!
ruquia tabassum wrote:Still i have a Doubt when server cannot access the client local file system.... now if i dont want to show the open save and cancel box just directly save the file on client machines local file system and when i write like this where should the FileOutputStream point to
You don't understand it? First forgot about Java at all and imagine that I am here and I have a folder at "c:/foo/bar" and that you are there and have a file "file.ext", how would you write it to my disk right now? If you can, just do the same thing with Java. If you can't (you can't), then you can't do it with Java either. Also try to think about why that isn't possible.