I am working on a jsp application and I have a download zip file feature
I have done
@RequestMapping(value = {"/retrieve"}, method = RequestMethod.POST)
public void logDownload(@RequestBody ResponseDto responseDto, Model model, HttpServletResponse response) throws ServletException, IOException {
Byte[] arraObj=downloadService.getdownloadFile();
response.setContentType("application/octate-stream");
response.setHeader("Content-Disposition","attachment;filename=user.zip",
response.getOutputStream().write(arraObj);
}
I am making a ajax call for this controller
JSP Side code
$.ajax({
type: 'POST',
url: "${pageContext.request.contextPath}/retrieve",
headers: { "X-CSRF-TOKEN": token },
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(retrieveDto),
success: function (res) {
window.location = "${pageContext.request.contextPath}/result";
},
error: function (e) {
// window.location="${pageContext.request.contextPath}/result";
console.log("There was an error with your request..." + JSON.stringify(e));
}
});
I am unable to download the file Can someone tell me how to fix this issue