SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void getReporte2(String ruta, String op) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  2.     Connection conexion;
  3.     Class.forName("com.mysql.jdbc.Driver").newInstance();
  4.     conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/basedatos", "usuario", "contrasenia");
  5.     String path = JSFUtil.getPath() + "/resources/images/membrete.png";
  6.     //Se definen los parametros si es que el reporte necesita
  7.     Map parameter = new HashMap();
  8.     parameter.put("operador", op);
  9.     parameter.put("P_RUTAIMAGEN", path);
  10.  
  11.     try {
  12.         File file = new File(ruta);
  13.  
  14.         HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
  15.  
  16.         httpServletResponse.setContentType("application/pdf");
  17.         httpServletResponse.addHeader("Content-Type", "application/pdf");
  18.  
  19.         JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(file.getPath());
  20.  
  21.         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, conexion);
  22.  
  23.         JRExporter jrExporter = null;
  24.         jrExporter = new JRPdfExporter();
  25.         jrExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  26.         jrExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, httpServletResponse.getOutputStream());
  27.  
  28.         if (jrExporter != null) {
  29.             try {
  30.                 jrExporter.exportReport();
  31.             } catch (JRException e) {
  32.                 e.printStackTrace();
  33.             }
  34.         }
  35.  
  36.     } catch (Exception e) {
  37.         e.printStackTrace();
  38.     } finally {
  39.         if (conexion != null) {
  40.             try {
  41.                 conexion.close();
  42.             } catch (Exception e) {
  43.                 e.printStackTrace();
  44.             }
  45.         }
  46.     }
  47. }
  48.    
  49. public void verReporte2(String ape) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
  50.  
  51.     reporteDetalle rDetalle = new reporteDetalle();
  52.  
  53.     FacesContext facesContext = FacesContext.getCurrentInstance();
  54.     ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
  55.     String ruta = servletContext.getRealPath("/resources/reportes/deudaXalumno.jasper");
  56.  
  57.     //le pasamos los paramtros al reporte
  58.     rDetalle.getReporte2(ruta, ape);
  59.     //rCliente.getReporte(ruta);        
  60.     FacesContext.getCurrentInstance().responseComplete();
  61. }
  62.    
  63. <p:menuitem value="Listado de Alumnos con deudas" actionListener="#{alumnoDataController.verReporte2(loginBean.toString())}" icon="ui-icon-close" ajax="false"/>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top