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