wood burning stoves 2.0*
The moose likes JSP and the fly likes can we export the data from jsp page to a excel sheet with out a database hit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "can we export the data from jsp page to a excel sheet with out a database hit" Watch "can we export the data from jsp page to a excel sheet with out a database hit" New topic
Author

can we export the data from jsp page to a excel sheet with out a database hit

Srikanth Adapa
Ranch Hand

Joined: Aug 21, 2008
Posts: 56
Hi all,

I have retrieved data from back end to jsp page. I have used MIME TYPE to export the same data to an excel sheet. But I have used the similar code written for retrieval of data into jsp page. i.e., I was using the same logic twice to retrieve the data, and hitting the data base twice. Is there any way to export the data to excel directly from jsp page, rather than hitting the database again. Pl let me know if any suggestions.


Many thanks in advance
Mansi Mishra
Ranch Hand

Joined: Dec 26, 2008
Posts: 50
I guess you will have the list with the data at the server side, you could reuse that...
no need to hit the db again


http://splashpress.blogspot.com
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The only way is to store it in memory.

The question left is: is the eaten up memory space really worth a save in the DB hit?

That said, fooling the browser with an invalid content-type/disposition response header so that it opens the request in Excel isn't the way you should follow. There is no guarantee that it will work at all platforms, all browsers and all Excel versions. Use a real Java API for Excel files which can create real .xls files, for example Apache POI HSSF/XSSF. More easy is to send the data as a CSV file, every Excel version supports the CSV format. There are libraries out for this as well, e.g. OpenCSV, CSV4J, JavaCSV, etc. If you're smart, you could even write it yourself in only 30 lines of code.
Srikanth Adapa
Ranch Hand

Joined: Aug 21, 2008
Posts: 56

Bauke,

There are multiple reports being generated from the database and it is required to export to excel sheet for every individual report. so, it definitely counts the DB hits.

But currently, I am concerned to export the data that was already retrieved on the page to an excel sheet. I have done the same by adding a mime type for the same code as a seperate file.


But it was required to hit the database again in this scenario.

will there be any other option of using the data that was retrieved in the jsp as a cache to open an excel sheet with the same data?

Please suggest me with a proper option.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Too bad that you still sticks in this wrong direction.

At any way, you have no other options. Either store it in memory or hit the DB again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we export the data from jsp page to a excel sheet with out a database hit