This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP File Download

 
Buffalo Soldier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
Thanks ...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Buffalo Soldier",
Welcome to the ranch. You may not be aware of the ranch Naming Policy. Please read it carefully and change your name accordingly (obviously fake names are not allowed). Thank you.
 
Buffalo Soldier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have preferred a more helpful response but n e way i'll try and do that ...
 
cesar valencia
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

(from a previous post of mine)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do so before your next post.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.]
 
Buffalo Soldier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic