Download file with ajax() POST request via Spring MVC

后端 未结 5 717
予麋鹿
予麋鹿 2020-12-06 11:24

I try to download a file. The action is triggered by ajax() POST request. The request sends data in JSON format to the controller. The controller gener

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 11:51

    Ajax is not going to help you try with hidden form approach

    pass you json through form field on click of of your download button submit form

    $('#formid').submit();

    then in server side

    response.setContentType("application/vnd.ms-excel");
                response.setHeader("Content-Disposition", "attachment; filename=filnemae.fileformat");
    
     ServletOutputStream out = res.getOutputStream();
    

    write on ouput stream then close or flush

    if you are sending large data through post update postsize in server.xml

提交回复
热议问题