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
| public class SendMessage implements Job {
private ServletContext servletContext;
private void createPdfRendezvous() {
HttpServletResponse response = (HttpServletResponse) this.servletContext;
Connection connection = null;
@SuppressWarnings("unused")
Statement statement = null;
String pathreport = ServletContextListner.getApplicationCntx().getRealPath("/")
+"report\\rpt_test.jasper";
File filereport = new File(pathreport);
try{
connection = Database_report.getConnection();
statement = connection.createStatement();
@SuppressWarnings("rawtypes")
Map parameters = new HashMap();
@SuppressWarnings("unchecked")
byte[] bytes = JasperRunManager.runReportToPdf(filereport.getPath(),parameters,connection);
response.setHeader("Content-Type", "application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream outStream = response.getOutputStream();
outStream.write(bytes, 0, bytes.length);
outStream.flush();
outStream.close();
} catch (Exception e) {
// TODO: handle exception
System.err.println(e.getMessage());
}
}
public void execute(JobExecutionContext context) throws JobExecutionException {
createPdfRendezvous();
}
} |
Partager