title: how to dynamically generate pdf using servlet
body: <p>I am generating a pdf using <em>JasperReports</em> in <em>JSP</em>, servlet. I am passing string parameter to the report. When I try to  generate single pdf, the pdf is generated nicely but when I try to generate two pdf, for the 1st parameter, pdf is generated but for the 2nd parameter, pdf is not generate. </p>
  
  <p>I'm passing the parameters through a loop.</p>
  
  <pre class="lang-java prettyprint-override"><code>String array[]={"1233","234"};
  HashMap params = new HashMap();
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection cn=DriverManager.getConnection("jdbc:oracle:thin:@103.179.1.218:1521:tims","scoot","tiger");
  
  for(int i=0;i&lt;array.length;i++) {
      params.put("seller_name",array[i]);
  
      JasperDesign jasperDesign = JRXmlLoader.load(getServletContext().getRealPath("/")+"report\\CForm.jrxml");
      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
      JasperPrint jasperprint = JasperFillManager.fillReport(jasperReport,params, cn);
      byte[] pdfasbytes = JasperExportManager.exportReportToPdf(jasperprint);
      ServletOutputStream outstream=response.getOutputStream();
      response.setContentType("application/pdf");
      response.setContentLength(pdfasbytes.length);
      String fileName="report"+i+".pdf";
      response.setHeader("Content-disposition", "attachement; filename="+fileName);
      outstream.write(pdfasbytes);
      JRExporter exporter = new JRPdfExporter();
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperprint);
      exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outstream);
      params.clear();
  
  }
  </code></pre>