title: How to display a JasperReports pdf file in an iframe?
body: <p>in currently I run my pdf report using JasperReports when clicking on report button the pdf report run with another browser tab but now I want to run the report on my JSP page using iframe tag. please help me to view / embedded jasper report on my web page.................................</p>
  
  <p>everybody can give me an example.</p>
  
  <p><strong>Html code is</strong></p>
  
  <pre><code>  &lt;div class="col-md-12"&gt;
                  &lt;!-- begin panel --&gt;
                  &lt;div class="panel panel-inverse" data-sortable-id="form-stuff-2"&gt;
                      &lt;div class="panel-heading"&gt;
                          &lt;div class="panel-heading-btn"&gt;
                              &lt;a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"&gt;&lt;i class="fa fa-expand"&gt;&lt;/i&gt;&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;h4 class="panel-title"&gt;Ship Service Report Page &lt;/h4&gt;
                      &lt;/div&gt;
                         &lt;div class="panel-body"&gt;
                          &lt;form class="form-horizontal"&gt;
  
                             &lt;div class="form-group"&gt;
                                  &lt;label class="col-md-2 control-label"&gt;Ship Name&lt;/label&gt;
                                  &lt;div class="col-md-4"&gt;
                                    &lt;select name="" class="form-control" id="shipNam" name="shipNam"&gt;
                                          &lt;option value="" selected="selected"&gt;Select Ship name&lt;/option&gt;
                                          &lt;s:iterator value="reportInfos" status="rowstatus"&gt;
                                          &lt;option value="&lt;s:property value='shipNo' /&gt;"&gt;&lt;s:property value='shipName' /&gt;&lt;/option&gt;
                                          &lt;/s:iterator&gt;
                                      &lt;/select&gt;
                                  &lt;/div&gt;
                                    &lt;/div&gt;
                               &lt;div class="form-group"&gt;  
                                  &lt;label class="col-md-2 control-label"&gt;From Date&lt;/label&gt;
                                  &lt;div class="col-md-3"&gt;
                                      &lt;input type="text" class="form-control" name="fromDate" id="fromDate" placeholder="Select Date" value="" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                            &lt;div class="form-group"&gt;  
                                  &lt;label class="col-md-2 control-label"&gt;To Date&lt;/label&gt;
                                  &lt;div class="col-md-3"&gt;
                                      &lt;input type="text" class="form-control" name="toDate" id="toDate" placeholder="Select Date" value="" /&gt;
                                  &lt;/div&gt;
                             &lt;/div&gt;
  
                              &lt;div class="form-group col-md-6"&gt;
                                  &lt;label class="col-md-4 control-label"&gt;Report Format&lt;/label&gt;
                                  &lt;div class="col-md-8"&gt;
                                      &lt;label class="radio-inline"&gt;
                                          &lt;input type="radio" name="optionsRadios" id="option1" value="pdf" checked /&gt;
                                          PDF
                                      &lt;/label&gt;
                                      &lt;label class="radio-inline"&gt;
                                          &lt;input type="radio" name="optionsRadios" id="option2" value="xls" /&gt;
                                          Excel
                                      &lt;/label&gt;
                                  &lt;/div&gt;
                            &lt;/div&gt;
                              &lt;div class="form-group"&gt;                                  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;button type="button" class="btn btn-sm btn-success" onclick="getShipServiceReport('shipNam','toDate' , 'fromDate')"&gt;View&lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
               &lt;/div&gt;
                  &lt;!-- end panel --&gt;
         &lt;/div&gt;
  </code></pre>
  
  <p><strong>my js function/report calling function</strong></p>
  
  <pre><code>    function getShipServiceReport(ship_no,to_date, fromDate){ 
          var shipNos=document.getElementById(ship_no).value;
          var toDate=document.getElementById(to_date).value;
          var fromDate=document.getElementById(fromDate).value;
          var fileType=$('input[name="optionsRadios"]:checked').val();
          var ajaxURL = "getShipServiceReportRT.do?ship_no="+shipNos+"&amp;to_date="+toDate+"&amp;fileType="+fileType+"&amp;fromDatee="+fromDate;          
          window.open(ajaxURL,'_blank');
   //$("#documentArea.html('&lt;iframe src='"+ajaxURL+"' frameBorder='0' style='height:1200px;width:100%;'&gt;&lt;/iframe&gt;')"); 
  
      }
  </code></pre>
  
  <p><strong>Java Action class</strong></p>
  
  <pre><code>public void getShipServiceReport()throws JRException, ServletException, IOException{
      Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
      parameters.put("shipNo", ship_no);
      parameters.put("fromDate", fromDatee);
      parameters.put("toDate", to_date);
      System.out.println("Parameter"+ship_no);
      String filename="shipServiceInformation.jasper";
      String reportType=fileType;
      showReport("",parameters,filename,reportType);
  
      }
  
  public static void showReport(String key, Map&lt;String, Object&gt; parameters, String filename, String reportType)
          throws JRException, ServletException, IOException {
      Connection connection = null;
      HttpServletResponse response = ServletActionContext.getResponse();
      String outputFileName = "report_" + key;
  
      connection = DBC.openCon();
  
      ServletContext context = ServletActionContext.getServletContext();
      String path = context.getRealPath("/");
  
      JasperPrint jasperPrint = JasperFillManager.fillReport(path + "jasper" + "/" + filename, parameters,
              connection);
      OutputStream ouputStream = response.getOutputStream();
      JRExporter exporter = null;
  
      if ("pdf".equalsIgnoreCase(reportType)) {
  
          response.setContentType("application/pdf");
          response.setHeader("Content-disposition", "inline;filename=" + outputFileName + "." + reportType);
          exporter = new JRPdfExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
          System.out.println("Report Created");
      } else if ("rtf".equalsIgnoreCase(reportType)) {
  
          response.setContentType("application/rtf");
          response.setHeader("Content-disposition", "inline;filename=" + outputFileName + "." + reportType);
          exporter = new JRRtfExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  
      } else if ("html".equalsIgnoreCase(reportType)) {
  
          exporter = new JRHtmlExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  
      } else if ("xls".equalsIgnoreCase(reportType)) {
  
          response.setContentType("application/xls");
          response.setHeader("Content-disposition", "inline;filename=" + outputFileName + "." + reportType);
          exporter = new JRXlsExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  
      } else if ("csv".equalsIgnoreCase(reportType)) {
  
          response.setContentType("application/xls");
          response.setHeader("Content-disposition", "inline;filename=" + outputFileName + "." + reportType);
          exporter = new JRCsvExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
      }
  
      try {
          // JasperViewer.viewReport(jasperPrint, true); // for direct print
          exporter.exportReport();
  
      } catch (JRException e) {
          System.out.println(e);
      } finally {
          if (ouputStream != null) {
              try {
                  ouputStream.close();
              } catch (Exception ex) {
                  System.out.println(ex);
              }
          }
      }
  }
  </code></pre>