How to pop up a save prompt box after java uses poi to implement excel export

Whether you use poi or use jxl to export excel, you need to use the stream

One is outputstrean, the other is fileoutputstream

The first: If you want to pop up the save prompt box, you must add the following three sentences
response.setContentType("application/vnd.ms-excel; charset=utf-8");
response.setHeader("Content-Disposition","attachment ;filename="+filename);
response.setCharacterEncoding("utf-8");
OutputStream os=response.getOutputStream();
When using the first one, I use the ajax request. As a result, excel cannot be exported. In the end, I directly requested that it can be exported . The
reason is: Ajax also uses the response.getWriter() method to return the data results. Although I gave up the returned write stream writer parameter, ajax still defaults to it. The removal is used, the stream has been occupied, and of course nothing can be returned.
The second:
use FileOutputStream in action
fos=new FileOutputStream(file);
at this time, you can use ajax request, return the file path after the export is successful, use window.open(path) in the page; you can open the exported excel file

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327042800&siteId=291194637