title: Calling jasper report from jsp page with parmeter
body: <p>I am calling a index page which sends parameter to  page that runs a jasper report in PDF. but when i run the project i got the problem in generating PDF  says PDF format might not right or corrupted(Mozilla and IE11)</p>
  
  <p>"index.jsp"</p>
  
  <pre><code>&lt;form method="POST" action="ShowPdf.jsp"&gt;
      &lt;input type="text" value="" id ="personId" name="personId"&gt;
      &lt;input type="submit" value="show"&gt;  
  &lt;/form&gt;
  
  
  int id=Integer.parseInt(request.getParameter("personId"));            
  try
  {
      Connection conn=null;
      //Connecting to the MySQL database
  
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      conn = DriverManager.getConnection("jdbc:mysql:/localhost:3306/bd_hospital_nikdu", "root", "Admin123");
  
      File reportFile = new File(application.getRealPath("//reports//newReport2.jasper"));//your report_name.jasper file
      Map parameters = new HashMap();
      parameters.put("personId",id);
  
      byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, conn);
  
      //byte[] bytes = JasperRunManager.runReportToHtmlFile(reportFile.getPath(),null, conn).getBytes();
  
      response.setContentType("application/pdf");
      response.setContentLength(bytes.length);
  
      ServletOutputStream outStream = response.getOutputStream();
      outStream.write(bytes, 0, bytes.length);
  
      outStream.flush();
      outStream.close();
  
  }
  catch (Exception ex) {
      ex.printStackTrace();
  } 
  </code></pre>