Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Srikanth Adapa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic