aspose file tools*
The moose likes JSP and the fly likes JSP File Download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP File Download" Watch "JSP File Download" New topic
Author

JSP File Download

Buffalo Soldier
Greenhorn

Joined: Feb 17, 2009
Posts: 3
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

"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.


[My Blog]
All roads lead to JavaRanch
Buffalo Soldier
Greenhorn

Joined: Feb 17, 2009
Posts: 3
I would have preferred a more helpful response but n e way i'll try and do that ...
cesar valencia
Ranch Hand

Joined: Oct 14, 2008
Posts: 33
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)


scjp5, scwcd5
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Please do so before your next post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

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

Joined: Feb 17, 2009
Posts: 3
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 !!!)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP File Download