I am sorry folks if this question has already been answered ...but i searched the net quite extensively for this solution but could not find any ...
I have got this jsp page which displays some data in a table (of course dynamically) ... and the same thing is getting written to a csv file at the same time ... i want to have a hyperlink that when clicked on will prompt me to download the same file ...
the best that i have been able to do is that it displays that file in the browser ...
there's an easy way, it just requires you to create a servlet and have the link point to the servlet. Put your data in session and read it on the servlet, or repeat the logic to generate the data in the servlet, that's up to you.
If you know the location of the .csv file it should be easy to have the link point to the file. Depending upon how the browser is configured to deal with .csv files, it make display it in-browser or prompt the user to download it.
If you need more control over the process, you could write a servlet to stream the file and set the content-disposition header as appropriate.
[Edit: cesar snuck his post in while I was typing. Yeah, that's the idea if a direct link will not suffice.]
Joined: Feb 17, 2009
Thanks a lot guys. But I found out another way and (a better-suited one at that for me ). After creating the table I have just placed a button underneath it which will export the table content to an excel file.
I am looking to put just the table in another jsp file so that none other than the table contents will get exported to the excel sheet.
By the way I've got a new problem though ... whenever I am opening the exported table in excel instead of showing data like 1-2 as it is, it is showing things like 2nd Feb or something. Any idea how to get around this? (I think Excel is smarter than we thought or we needed it to be in this case !!!)