问题
Hello I have a Java web app made in JSF...when you press a button it should write a string in a pdf file and download it. Here is the code:
String cont = "DATA CREARE: " + data_creare3 + "\n" + "CIF: " + cif3 + "\n" + "ID SOLICITARE: " + id_solicitare3 + "\n" + "DETALII" + detalii3 + "\n" + "TIP: " + tip3 + "\n" + "ID: " + id3;
startDownload(cont.getBytes(), "id.pdf");
This is the String and the method being called and here is the function that makes the download..
private void startDownload(byte[] continut, String denumire) throws IOException{
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// externalContext.responseReset();
externalContext.setResponseHeader("Cache-Control", "public");
externalContext.setResponseHeader("Pragma", "public");
externalContext.setResponseHeader("Content-Type", "application/pdf");
externalContext.setResponseHeader("Content-Length",
Integer.toString(continut.length));
externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + denumire + "\"");
externalContext.getResponseOutputStream().write(continut);
facesContext.responseComplete();
}
When I click the button to download it says:
emptyResponse: An empty response was received from the server. Check server error logs
The server error logs say:
2020-02-03 09:18:44,438 WARNING [javax.enterprise.resource.webcontainer.jsf.application] (default task-2) JSF1063: WARNING! Setting non-serializable attribute value into HttpSession (key: logic, value class: com.serban.Logic).
What should I do to make it work ? Thanks in advance
来源:https://stackoverflow.com/questions/60034812/download-pdf-file-from-java-web-app-made-in-jsf