I want to export Excel by browser. If I click the export button I can see information in Chrome network, but it did not download. I can download excel to my project folder, but how to export excel through the browser? Below the Ajax and controller codes.
This is my Excel util:
public class WriteExcel {
/**
 * @param answerList
 * @return
 */
public static void writeData(List<Answer> answerList, String paperName, HttpServletResponse response) throws IOException {
    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet("test");
    for(int i=0; i<answerList.size();i++){
        Answer answer = answerList.get(i);
        Row row = sheet.createRow(i);
        Cell cell = row.createCell(0);
        cell.setCellValue(answer.getAnswerpname());
        List<AnswerReceive> answerReceives = JSON.parseArray(answer.getAnswerdata(), AnswerReceive.class);
        for(int j=0; j<answerReceives.size(); j++){
            AnswerReceive answerReceive = answerReceives.get(j);
            Cell tmp_cell = row.createCell(j+1);
            tmp_cell.setCellValue(answerReceive.getData());
        }
    }
    response.setContentType("application/octet-stream;charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment;filename="
            .concat(String.valueOf(URLEncoder.encode(paperName, "UTF-8"))));
    OutputStream out = response.getOutputStream();
    workbook.write(out);
}
}
My controller:
@PostMapping("/export")
@ResponseBody
public Object exportExcel(@RequestParam("paperId") String paperId, HttpServletResponse response) throws IOException {
    List<Answer> answerList = answerService.getData(paperId);
    WriteExcel.writeData(answerList, "test", response);
}
My Ajax:
$("button[name='export']").click(function () {
    $.ajax({
        url: "/export",
        type: "post",
        data: {"paperId":$(this).attr("data-paper-id")},
        success: function (data) {
            console.log(data.flag);
            console.log(data.Message);
        }
    })
})
 
     
     
    