JSP generating Excel spreadsheet (XLS) to download

excel, export, java, jsp, tomcat

Solution

While you can use a full fledged library like JExcelAPI, Excel will also read CSV and plain HTML tables provided you set the response MIME Type to something like "application/vnd.ms-excel".

Depending on how complex the spreadsheet needs to be, CSV or HTML can do the job for you without a 3rd party library.

Problem

I have this application I'm developing in JSP and I wish to export some data from the database in XLS (MS Excel format). Is it possible under tomcat to just write a file as if it was a normal Java application, and then generate a link to this file? Or do I need to use a specific API for it? Will I have permission problems when doing this?

Original source