title: How open a new tab using servlet response?
body: <p>I want to open a new tab when I run <code>index.jsp</code> file in a web application . And I have used <code>Show.java</code> (a servlet) to perform that . The current situation is when I click the <code>Print</code> button in <code>index.jsp</code> , the content page which I want to open in a new tab is displaying on the current tab . I want to do it using servlet response and not using <code>javascript</code> or <code>jquery</code> .   </p>
  
  <p>This is the I've written in <code>index.jsp</code> file ,</p>
  
  <pre><code>&lt;form action="Show"&gt;            
      &lt;input type="submit" value="Print"/&gt;
  &lt;/form&gt;
  
  &lt;%@page import="net.sf.jasperreports.engine.export.JRPdfExporter" %&gt;
  
  &lt;%
     JRPdfExporter export = (JRPdfExporter)request.getAttribute("exportIndentObject");
     if (export != null){
           JRPdfExporter export1 = (JRPdfExporter) session.getAttribute("exportIndentObject");
           export1.exportReport();
      }%&gt;
  </code></pre>
  
  <p>This is <code>Show.java</code> which I use to keep content,</p>
  
  <pre><code>String param ="Terance";     
    Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
    map.put("param", param);                
    JRPdfExporter jRPdfExporter = new  JRPdfExporter();                                                                       jRPdfExporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,                                      this.print();");
  
    String jsaperFile="C:\\Users\\user\\Desktop\\Terance\\Jasper\\JasperReport\\src\\java\\jasper\\Report.jrxml";
  System.out.println(jsaperFile);
  try
                      {
                          String report=JasperCompileManager.compileReportToFile(jsaperFile);
  
                          File file=new File(report);
                          if(!file.exists()){
                              throw new JRException("Cannot find the given file .");
                          }
  
                          JasperPrint jasperPrint=JasperFillManager.fillReport(report, map);
                          byte[] exportReportToPdf = JasperExportManager.exportReportToPdf(jasperPrint);
  
                          ServletOutputStream sout = response.getOutputStream();
                          response.setContentType("application/pdf;");
  
                          jRPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                          jRPdfExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, sout);
                          jRPdfExporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();");
  
                          request.setAttribute("exportIndentObject", jRPdfExporter);
  
                          response.setContentType("application/pdf");
                          response.setHeader("Content-disposition","inline; filename=\"myReport.pdf\"");        
  
  
                          sout.write(exportReportToPdf);      
                          sout.flush();
                          sout.close();              
  
                      } catch (JRException ex)
                      {
                          ex.printStackTrace();
                      }
  </code></pre>
  
  <p>When I use <code>response.redirect();</code> , I couldn't get even the <code>index.jsp</code> file in browser .</p>