generate pdf file from jasper report with servlet java code -
i have jasper report, put in same package servlets, need generate pdf file it, code doesn't work , doesn't gives error
public void print(string numbac , httpservletrequest request, httpservletresponse response) { try { jasperdesign jasperdesign = jrxmlloader .load("fiche.jrxml"); string sql = "select * etudiant " + "inner join filiere on etudiant.code_f=filiere.code_f " + "inner join lieu_nais on etudiant.code_lieu=lieu_nais.code_lieu " + "inner join montant on etudiant.code_m=montant.code_m bac='" + numbac + "'"; jrdesignquery newquery = new jrdesignquery(); newquery.settext(sql); jasperdesign.setquery(newquery); jasperreport report = jaspercompilemanager .compilereport(jasperdesign); //jasperprint print = jasperfillmanager.fillreport(report, null, cnx); //jasperviewer.viewreport(print); byte[] bytestream; bytestream = jasperrunmanager.runreporttopdf(report, null, cnx); outputstream outstream = response.getoutputstream(); response.setheader("content-sisposition", "inline,filename="+download_file_name); response.setcontenttype(file_type); response.setcontentlength(bytestream.length); outstream.write(bytestream, 0, bytestream.length); } catch (exception e) { e.printstacktrace(); } }
even if want generate jasper preview doesn't shown (code in comment)
first of all, have spelling error here:
response.setheader("content-sisposition", "inline,filename="+download_file_name);
it should "disposition" instead of "sisposition":
response.setheader("content-disposition", "inline,filename="+download_file_name);
also, try using "attachment" instead of "inline":
response.setheader("content-disposition", "attachment,filename="+download_file_name);
and flush , close outstream:
outstream.flush(); outstream.close();
hope helps!
Comments
Post a Comment