Download file with ajax() POST request via Spring MVC

后端 未结 5 720
予麋鹿
予麋鹿 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:56

    As the comments said you can't do it with an ajax call, but you can do it with plain Javascript.

    function getLicenseFile() {
        var downloadUrl = "${pageContext.request.contextPath}/licenses/rest/downloadLicenseFile";
        // (optionally) provide the user with a message that the download is starting
        window.location.href = downloadUrl;
    }
    

    Note the use of ${pageContext.request.contextPath}, which is preferred over <%=request.getContextPath()%>.

提交回复
热议问题