title: How to open PDF file in JSP
body: <p>I have a web application in which I am creating PDF reports using <em>JasperReport</em>. I have hosted my website.</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@page import="java.sql.*" %&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JasperExportManager"%&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JasperExportManager"%&gt;
  &lt;%@page import="net.sf.jasperreports.view.JasperViewer"%&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JasperPrint"%&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JasperReport"%&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JasperFillManager"%&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JRResultSetDataSource"%&gt;
  &lt;%@page import="net.sf.jasperreports.engine.JasperCompileManager"%&gt;
  &lt;%@page import="net.sf.jasperreports.*"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;JSP Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;%
          String invno=request.getParameter("invno");
          try {
          String absolutePath = getServletContext().getRealPath("clDS_Close.jrxml");
          JasperReport jasperReport=JasperCompileManager.compileReport(absolutePath);
          Class.forName("com.mysql.jdbc.Driver");
          Connection conn =   DriverManager.getConnection("jdbc:mysql://localhost:3306/t_fleet","root","aadi");
  
          Statement stmt = null;
          ResultSet rset = null;
          Statement st2=conn.createStatement();
  
          String queryString = "select tbl_invoice.*,tbl_package.package_name,tbl_package.basic_hr,tbl_package.basic_km,tbl_package.amount from tbl_invoice inner join tbl_package on tbl_invoice.package_id=tbl_package.package_id where tbl_invoice.invoice_no="+invno+"";
          stmt = conn.createStatement();
          rset = stmt.executeQuery(queryString);
          JRResultSetDataSource jasperReports = new JRResultSetDataSource(rset);
          JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, jasperReports);
  
          String filename=null;
          filename="CL"+invno+".pdf";
  
          //Report saved in specified path
          JasperExportManager.exportReportToPdfFile(jasperPrint,filename);
  
          //Report open in Runtime
          String createdFile = getServletContext().getRealPath(filename);
          out.println(createdFile);
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " +filename);
         } catch(Exception e) {
             out.println(e);
         }
      %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am accepting invoice number from user and opening PDF file for that invoice.</p>
  
  <p>My problem is my pdf file is getting created and stored to path but, I don't know how to open it. There is a method <code>RunTime.getRunTime.exec()</code> in windows. But I think this will not work because as I have hosted my web application to free domain, this method will not work there.
   Please tell me alternative for above method so that I can open my PDF file stored in specific path.</p>