3
In my work, I am developing a Java EE application, with web service REST (Jersey), Hibernate and Jquery on the front end. All my system requests use ajax and I am having difficulty generating the report and displaying it on the screen for the user (either by opening in the browser or downloading).
I would like to know the best way to do this, I have seen some places saying that it is not possible to open the PDF received by Ajax.
I have some filters that the user can choose to generate the report and I pass these filters through a POST to the web service that returns me like this (I think this part is right):
File relatorio = gerarRelatorioExtratoVendas(movimentos, usuarioLogado, filtros);
ResponseBuilder response = Response.ok(relatorio); response.type("application/pdf");
response.header("Content-Disposition", "attachment; filename=" + relatorio.getName());
return response.build();
Now I need to receive it and show it to the user, I am saving it in a temporary system folder.
From what I understand is missing attach the bytes of the file to the object
response
, would that be? It would be aresponse.contentLocation(new URI(relatorio.getPath()));
? It’s just a kick, the right way to do it might be something quite different than that!– Piovezan