Foros del Web » Programación para mayores de 30 ;) » Java »

Netbeans 6.8 + ireport 3.7.4

Estas en el tema de Netbeans 6.8 + ireport 3.7.4 en el foro de Java en Foros del Web. hola a todos, de antemano agradezco la ayuda que me puedan brindar. He hecho mi reporte y lo he pasado a PDF sin problemas pero ...
  #1 (permalink)  
Antiguo 17/09/2010, 20:51
 
Fecha de Ingreso: septiembre-2010
Mensajes: 7
Antigüedad: 13 años, 7 meses
Puntos: 0
Netbeans 6.8 + ireport 3.7.4

hola a todos, de antemano agradezco la ayuda que me puedan brindar.
He hecho mi reporte y lo he pasado a PDF sin problemas pero cuando quiero pasarlo a HTML no me carga me arroja la ruta:
G:\08\webPruebaMVC\build\web\Reportes\classic.html

El código de mi JSP es:


Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

/*importamos las librerías de JasperReports*/
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>

<%
/*Parametros para realizar la conexión*/
Connection conexion;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conexion = DriverManager.getConnection("jdbc:mysql://localhost/bdCurso","root","2010");

/*Establecemos la ruta del reporte*/
File reportFile = new File(application.getRealPath("Reportes//RepCursos.jasper"));

/* No enviamos parámetros porque nuestro reporte no los necesita asi que escriba cualquier
cadena de texto ya que solo seguiremos el formato del método runReportToPdf*/

Map parameters = new HashMap();
parameters.put("Nombre_parametro", "Valor_Parametro");

/*Enviamos la ruta del reporte, los parámetros y la conexión(objeto Connection)*/
byte[] bytes = JasperRunManager.runReportToHtmlFile(reportFile.getPath (), parameters, conexion).getBytes();
//        JasperRunManager.runReportToPdf(reportFile.getPath (), parameters,conexion);

/*Indicamos que la respuesta va a ser en formato PDF*/
//response.setContentType("application/pdf");
response.setContentType("text/html");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);

/*Limpiamos y cerramos flujos de salida*/
ouputStream.flush();
ouputStream.close();
%>
A espera de su ayuda
  #2 (permalink)  
Antiguo 18/09/2010, 00:58
 
Fecha de Ingreso: febrero-2010
Mensajes: 128
Antigüedad: 14 años, 2 meses
Puntos: 3
Respuesta: Netbeans 6.8 + ireport 3.7.4

Buenas! el ejemplo que conseguí yo hace tiempo funciona muy bien para los PDF y un poco peor para los HTML, pero pruebalo a ver si te va bien.

Suerte

Código JSP:
Ver original
  1. //EL PATH DIO PROBLEMAS EN WINDOWS, TUVE QUE USAR EL PATH DE WIN...
  2.  
  3.                     String filename = "\\" + request.getParameter("filename");
  4.                     String reporttype = request.getParameter("reporttype");
  5.  
  6.                     HashMap jasperParameter = new HashMap();
  7.                     jasperParameter.put("IdGrupo", Long.parseLong(idGrupo));
  8.  
  9.                    
  10.                     jasperParameter.put("NumEval", Long.parseLong("" + v.size()));
  11.  
  12.  
  13.  
  14.                     String path = getServletContext().getRealPath("informes") + filename + ".jasper";
  15.                     System.out.println(path);
  16.                     JasperPrint jasperPrint = JasperFillManager.fillReport(path, jasperParameter, conexion.getConnection());
  17.  
  18.                     OutputStream ouputStream = response.getOutputStream();
  19.                     JRExporter exporter = null;
  20.  
  21.                     if ("PDF".equalsIgnoreCase(reporttype)) {
  22.  
  23.                         response.setContentType("application/pdf");
  24.                         exporter = new JRPdfExporter();
  25.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  26.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  27.  
  28.                     } else if ("RTF".equalsIgnoreCase(reporttype)) {
  29.  
  30.                         response.setContentType("application/rtf");
  31.                         response.setHeader("Content-Disposition", "inline; filename=\"fichero.rtf\"");
  32.                         exporter = new JRRtfExporter();
  33.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  34.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  35.  
  36.                     } else if ("HTML".equalsIgnoreCase(reporttype)) {
  37.                         exporter = new JRHtmlExporter();
  38.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  39.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  40.  
  41.                     } else if ("XLS".equalsIgnoreCase(reporttype)) {
  42.  
  43.                         response.setContentType("application/xls");
  44.                         response.setHeader("Content-Disposition", "inline; filename=\"fichero.xls\"");
  45.                         exporter = new JRXlsExporter();
  46.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  47.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  48.  
  49.                     } else if ("CSV".equalsIgnoreCase(reporttype)) {
  50.  
  51.                         response.setContentType("application/csv");
  52.                         response.setHeader("Content-Disposition", "inline; filename=\"fichero.csv\"");
  53.                         exporter = new JRCsvExporter();
  54.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  55.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  56.  
  57.                     }
  58.  
  59.                     try {
  60.                         exporter.exportReport();
  61.                     } catch (JRException e) {
  62.                         throw new ServletException(e);
  63.                     } finally {
  64.                         if (ouputStream != null) {
  65.                             try {
  66.                                 ouputStream.close();
  67.                             } catch (IOException ex) {
  68.                             }
  69.                         }
  70.                     }
  #3 (permalink)  
Antiguo 18/09/2010, 08:24
 
Fecha de Ingreso: septiembre-2010
Mensajes: 7
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Netbeans 6.8 + ireport 3.7.4

Cita:
Iniciado por Denis127 Ver Mensaje
Buenas! el ejemplo que conseguí yo hace tiempo funciona muy bien para los PDF y un poco peor para los HTML, pero pruebalo a ver si te va bien.

Suerte

Código JSP:
Ver original
  1. //EL PATH DIO PROBLEMAS EN WINDOWS, TUVE QUE USAR EL PATH DE WIN...
  2.  
  3.                     String filename = "\\" + request.getParameter("filename");
  4.                     String reporttype = request.getParameter("reporttype");
  5.  
  6.                     HashMap jasperParameter = new HashMap();
  7.                     jasperParameter.put("IdGrupo", Long.parseLong(idGrupo));
  8.  
  9.                    
  10.                     jasperParameter.put("NumEval", Long.parseLong("" + v.size()));
  11.  
  12.  
  13.  
  14.                     String path = getServletContext().getRealPath("informes") + filename + ".jasper";
  15.                     System.out.println(path);
  16.                     JasperPrint jasperPrint = JasperFillManager.fillReport(path, jasperParameter, conexion.getConnection());
  17.  
  18.                     OutputStream ouputStream = response.getOutputStream();
  19.                     JRExporter exporter = null;
  20.  
  21.                     if ("PDF".equalsIgnoreCase(reporttype)) {
  22.  
  23.                         response.setContentType("application/pdf");
  24.                         exporter = new JRPdfExporter();
  25.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  26.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  27.  
  28.                     } else if ("RTF".equalsIgnoreCase(reporttype)) {
  29.  
  30.                         response.setContentType("application/rtf");
  31.                         response.setHeader("Content-Disposition", "inline; filename=\"fichero.rtf\"");
  32.                         exporter = new JRRtfExporter();
  33.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  34.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  35.  
  36.                     } else if ("HTML".equalsIgnoreCase(reporttype)) {
  37.                         exporter = new JRHtmlExporter();
  38.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  39.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  40.  
  41.                     } else if ("XLS".equalsIgnoreCase(reporttype)) {
  42.  
  43.                         response.setContentType("application/xls");
  44.                         response.setHeader("Content-Disposition", "inline; filename=\"fichero.xls\"");
  45.                         exporter = new JRXlsExporter();
  46.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  47.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  48.  
  49.                     } else if ("CSV".equalsIgnoreCase(reporttype)) {
  50.  
  51.                         response.setContentType("application/csv");
  52.                         response.setHeader("Content-Disposition", "inline; filename=\"fichero.csv\"");
  53.                         exporter = new JRCsvExporter();
  54.                         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  55.                         exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
  56.  
  57.                     }
  58.  
  59.                     try {
  60.                         exporter.exportReport();
  61.                     } catch (JRException e) {
  62.                         throw new ServletException(e);
  63.                     } finally {
  64.                         if (ouputStream != null) {
  65.                             try {
  66.                                 ouputStream.close();
  67.                             } catch (IOException ex) {
  68.                             }
  69.                         }
  70.                     }
--------------------------------------------------------------------------------------

Hola Denis127, te agradecería me pases las librerias que debo importar em especial para las clases: "JRPdfExporter" y "JRHtmlExporter" que son justamente las que necesito.
Gracias por tu ayuda.
  #4 (permalink)  
Antiguo 18/09/2010, 21:49
 
Fecha de Ingreso: septiembre-2010
Mensajes: 7
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Netbeans 6.8 + ireport 3.7.4

Hola a todos ya solucioné mi problema. Les comento que mi problema radicaba en que estaba colocando las librerias de ireport de una versión anterior, subsanado este problema todo ok.

Gracias a todos por su ayuda y sigan aportando con sus conocimientos a la comunidad.

Saludos

Etiquetas: html, ireport, netbeans
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:33.