JSP generating Excel spreadsheet (XLS) to download

后端 未结 6 1657
感动是毒
感动是毒 2020-11-27 07:01

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

6条回答
  •  春和景丽
    2020-11-27 07:09

    You will probably need a library to manipulate Excel files, like JExcelAPI ("jxl") or POI. I'm more familiar with jxl and it can certainly write files. You can generate them and store them by serving a URL to them but I wouldn't. Generated files are a pain. They add complication in the form on concurrency, clean-up processes, etc.

    If you can generate the file on the fly and stream it to the client through the standard servlet mechanisms.

    If it's generated many, may times or the generation is expensive then you can cache the result somehow but I'd be more inclined to keep it in memory than as a file. I'd certainly avoid, if you can, linking directly to the generated file by URL. If you go via a servlet it'll allow you to change your impleemntation later. It's the same encapsualtion concept as in OO dsign.

提交回复
热议问题