Código PHP:
<%@page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@page import="net.sf.jasperreports.view.JasperViewer"%>
<%@page import="net.sf.jasperreports.engine.JasperFillManager"%>
<%@page import="net.sf.jasperreports.engine.JasperReport"%>
<%@page import="net.sf.jasperreports.engine.JasperCompileManager"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.Map"%>
<%@page import="net.sf.jasperreports.engine.JasperRunManager"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.io.File"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="net.sf.jasperreports.engine.util.JRLoader"%>
<%
String r = request.getParameter("Nombre");
JasperPrint reporte_view;
Connection conn=null;
try
{
Class.forName("com.mysql.jdbc.Driver"); //se carga el driver
String url = "jdbc:mysql://localhost:3306/Reporte";
Connection con = DriverManager.getConnection(url, "root","chris");
out.print("conexion CTM! xD");
}
catch (Exception ex)
{
ex.printStackTrace();
}
File reportFile = new File(application.getRealPath("report1.jasper"));
Map parameters = new HashMap();
parameters.put("NOMBRE",r);
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath (),parameters,conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
%>