télécharger pdf généré depuis servlet avec jasper
j'ai un servlet contenant une méthode print() pour appeler un jasper report en pdf, mais ne fonctionne pas je ne trouve pas où est l'erreur
servlet
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public void print(String numBac,HttpServletRequest request, HttpServletResponse response) {
try {
JasperDesign jasperDesign = JRXmlLoader
.load("fiche.jrxml");
String sql = "SELECT * FROM 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 WHERE bac='"
+ numBac + "'";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport report = JasperCompileManager
.compileReport(jasperDesign);
byte[] byteStream = JasperRunManager.runReportToPdf(report, null, cnx);
OutputStream outStream = response.getOutputStream();
response.setHeader("Content-Disposition","inline, filename=fiche.pdf");
response.setContentType("application/pdf");
response.setContentLength(byteStream.length);
outStream.write(byteStream,0,byteStream.length);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet SignUp</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>M./Mlle. " + e.getNom()+"</h1> </br>");
out.println("<h1>"+msg+"</h1>");
out.println("</body>");
out.println("</html>");
} finally {
print(e.getBac(),request,response);
out.close();
}
} |