Ver Mensaje Individual
  #13 (permalink)  
Antiguo 20/07/2011, 04:14
Pelirr
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 4 meses
Puntos: 1
Respuesta: no encuentra url para cargar .jasper

Lo primero, muchas gracias a todos, habéis sido de gran ayuda. Tenías razón hkadejo con lo del iframe, lo que pasa que yo nunca lo había usado y no sabía ni que existía. Al final, la jsp llama a un servlet al pinchar en el botón de búsqueda, y el servlet consigue el objeto jasperprint que necesito. Y en la jsp, creo un objeto <iframe> dentro de un <div>, y ahí meto el jasperprint. Voy a poner los códigos porque seguro que a alguien le pasa como a mí y le vendrán muy bien. Repito, gracias a todos.

jsp
Código:
...
var operacionSeleccionada = $(document).find('#selectOperacion').val();

  						document.getElementById('informe').innerHTML = '<iframe name="informeFrame"  width="1520" height="550"></iframe>';
  						window.parent.frames["informeFrame"].location="/AODB2/operacionesDiarias.servlet?reportDateString="+fechaAComprobar+"&typeFlightSelected="+operacionSeleccionada + nombresParametros;
						//no se podría poner en este caso "<iframe src='/AODB2/operacionesDiarias.servlet?reportDateString='+variables width='1400' height='550'></iframe>"
						//debido a las comillas (tanto ' como  "), interfieren y no coge las variables para llevarla al action o al servlet

...
servlet
Código:
public class OperacionesDiariasServlet extends HttpServlet
{
	private static final long serialVersionUID = 7154490521050615751L;
	
	private Log logger = LogFactory.getLog(this.getClass());
	private static final String TITULO_INFORME = "tituloInforme";
	private static final String COMPANIA = "compania";
	private static final String NUMERO_VUELO = "numeroVuelo";
	private static final String FECHA_PROGRAMADA = "fechaProgramada";
	private static final String ESTADO_ACTUAL = "estadoActual";
	private static final String TIPO_VUELO = "tipoVuelo";
	private static final String TIPO_AERONAVE = "tipoAeronave";
	private static final String NUMERO_ASIENTOS = "numeroAsientos";
	private static final String NUMERO_PASAJEROS = "numeroPasajeros";
	private static final String OCUPACION = "ocupacion";
	private static final String REPORT_DATE_STRING = "reportDateString";
	
	private Collection<String> errorsList = new ArrayList<String>();

	@SuppressWarnings("unchecked")
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException 
	{
		Connection connection = null;

		Properties properties = new Properties();		
		String url = "";
		String user = "";
		String password = "";
 		
		try 
		{
			properties.load (this.getClass().getClassLoader().getResourceAsStream("es/indra/aodb/informes/web/action/informes/reportProperties/Report.properties"));
							//properties.getClass().getResourceAsStream("es/indra/aodb/informes/web/action/informes/reportProperties/Report.properties"));
			url = properties.getProperty("urlJasperReport");
			user = properties.getProperty("userJasperReport");
			password = properties.getProperty("passwordJasperReport");
		} 
		catch (FileNotFoundException e2) 
		{
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		catch (IOException e2) 
		{
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
		try 
		{
			connection = DriverManager.getConnection(url, user, password);
		} 
		catch (SQLException e) 
		{
			logger.debug("Error al conectar con DS de informes: " + e.getMessage());
			errorsList.add("Error al conectar con DS de informes: " + e.getMessage());
			e.printStackTrace();
			
		}
		
		JasperPrint jasperPrint = null;
		//String filename = "/es/indra/aodb/informes/web/informes/etc/ListadoOperacionesDiarias.jasper"; segun internet
		JasperReport listadoDiarioOperacionesJasperReport = null;
		
		String tituloInforme = request.getParameter(TITULO_INFORME);
		String compania = request.getParameter(COMPANIA);
		String numeroVuelo = request.getParameter(NUMERO_VUELO);
		String fechaProgramada = request.getParameter(FECHA_PROGRAMADA);
		String estadoActual = request.getParameter(ESTADO_ACTUAL);
		String tipoVuelo = request.getParameter(TIPO_VUELO);
		String tipoAeronave = request.getParameter(TIPO_AERONAVE);
		String numeroAsientos = request.getParameter(NUMERO_ASIENTOS);
		String numeroPasajeros = request.getParameter(NUMERO_PASAJEROS);
		String ocupacion = request.getParameter(OCUPACION);

		
		HashMap parameters = new HashMap();
		parameters.put("tituloInforme", tituloInforme);
		parameters.put("compania", compania);
		parameters.put("numeroVuelo", numeroVuelo);
		parameters.put("fechaProgramada", fechaProgramada);
		parameters.put("estadoActual", estadoActual);
		parameters.put("tipoVuelo", tipoVuelo);
		parameters.put("tipoAeronave", tipoAeronave);
		parameters.put("numeroAsientos", numeroAsientos);
		parameters.put("numeroPasajeros", numeroPasajeros);
		parameters.put("ocupacion", ocupacion);
		
		SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		String reportDateString = request.getParameter(REPORT_DATE_STRING);
		try 
		{
			Date fechaInformeDesde = formatoFecha.parse(reportDateString + " 00:00:00");			
			Date fechaInformeHasta = formatoFecha.parse(reportDateString + " 23:59:59");
			parameters.put("fechaInformeDesde", fechaInformeDesde);
			parameters.put("fechaInformeHasta", fechaInformeHasta);
		} 
		catch (ParseException e) {
			logger.error("No se han transformado bien las fechas desde y hasta de informe");
			errorsList.add("No se han transformado bien las fechas desde y hasta de informe");
			e.printStackTrace();
		}
		
		try 
		{
			//jasperPrint = JasperFillManager.fillReport(filename, parameters, connection); segun internet
			listadoDiarioOperacionesJasperReport = (JasperReport) JRLoader.loadObject(this.getClass().getClassLoader().getResourceAsStream("es/indra/aodb/informes/web/action/informes/reportsJasper/ListadoOperacionesDiarias.jasper"));
			jasperPrint = JasperFillManager.fillReport(listadoDiarioOperacionesJasperReport, parameters, connection);
            if (jasperPrint != null) 
            {
                logger.debug("Se va a mostrar el informe");
                //montar informe en JasperViewer y mostrar en el modulo de informes
                //JRViewer viewer = new JRViewer(jasperPrint);
                logger.debug("Informe mostrado");
                logger.debug("informe descargado");
                
                byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
                logger.debug("exportado a bytes");
                response.setContentType("application/pdf");
                response.setContentLength(bytes.length);
                response.setHeader( "Content-disposition", "inline; filename=reporte.pdf");
                ServletOutputStream ouputStream = response.getOutputStream();
                logger.debug("creada la salida ourputStream");
                ouputStream.write(bytes, 0, bytes.length);
                ouputStream.flush();
                ouputStream.close();
                
            } 
            else 
            {
                logger.error("No se ha generado el informe correctamente");
                errorsList.add("No se ha generado el informe correctamente");
            }
		} 
		catch (JRException e1) 
		{
			logger.debug(e1);
			errorsList.add(e1.getMessage());
			e1.printStackTrace();
		}
	}


	public Collection<String> getErrorsList() {
		return errorsList;
	}

	public void setErrorsList(Collection<String> errorsList) {
		this.errorsList = errorsList;
	}
	
}
Un saludo