Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
File exe_rpt = new File(request.getRealPath("reports/tableprint.jasper"));
Map parameters = new HashMap();
parameters.put("area", sql);
parameters.put("year", year);
JasperPrint jasperPrint = JasperFillManager.fillReport(exe_rpt.getPath(),parameters,conn);
request.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
byte[] bytes = JasperRunManager.runReportToPdf(exe_rpt.getPath(),parameters,conn);
response.setContentType("applicationf");
response.setHeader("Content-Disposition","tableprint.pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
JRPdfExporter pdf=new JRPdfExporter ();
pdf.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
pdf.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
pdf.exportReport();
ouputStream.write(bytes,0,bytes.length);
ouputStream.flush();
ouputStream.close();
conn.close();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
File exe_rpt = new File(request.getRealPath("reports/tableprint.jasper"));
Map parameters = new HashMap();
parameters.put("area", sql);
parameters.put("year", year);
JasperPrint jasperPrint = JasperFillManager.fillReport(exe_rpt.getPath(),parameters,conn);
request.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
byte[] bytes = JasperRunManager.runReportToPdf(exe_rpt.getPath(),parameters,conn);
response.setContentType("applicationf");
response.setHeader("Content-Disposition","tableprint.pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
JRPdfExporter pdf=new JRPdfExporter ();
pdf.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
pdf.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
pdf.exportReport();
ouputStream.write(bytes,0,bytes.length);
ouputStream.flush();
ouputStream.close();
conn.close();