I create .xlsx file on a server by using Apache POI library. I just can't understand whats steps I should to perform to download this file when user click on a button? This button invoke method in JAX-RS which create .xlsx, it didn't write it to server. Is it possible to download it directly to user (without writing to the server's disk), i.e. open popup where user being asked if he want to download this file?
I tried this solution but it doesn't work:
File file = new File("test.xlsx");
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=new-excel-file.xls");
return response.build();
And ajax code:
$.ajax({
type: "POST",
url: 'api/export',
data: JSON.stringify(chartData),
headers : {
'Accept' : 'application/json',
'Content-Type' : 'application/json'
},
success: function(data){
alert(data);
}
});
And I get error 406 error, I suspect that I should define that ajax requests accept returned data type, but don't know which data type is? Thank you.