Jump to content
We've recently updated our Privacy Statement, available here ×

Problems with printing a report


aggelos

Recommended Posts

Hi all,

 

i have a little problem with a web application. I have created a jsp that shows a report and it has a applet button to print the report that display the validation to print. The button is showed, but whe i push it, nothig happend...

 

this is the jsp code:

 

<%--

/*

* Nombre de la clase: HojaDeVida.jsp

*

* Descripción: Interfaz Gráfica de la consulta del historial de un Equipo

*

* Información de la versión: 1.0

*

* Fecha de creación: 2 de Junio de 2006

*

* Autor de la clase: Elsa Viviana Charry Lopez

*

* Fecha de modificación: 21 de Julio de 2006

*

* Autor de la modificación: Elsa Viviana Charry Lopez

*/

--%>

 

<%@ page import="net.sf.jasperreports.view.JasperViewer" %>

<%@ page import="net.sf.jasperreports.j2ee.servlets.ImageServlet" %>

<%@ page import="net.sf.jasperreports.engine.export.JRHtmlExporter" %>

<%@ page import="net.sf.jasperreports.engine.export.JRHtmlExporterParameter" %>

<%@ page import="net.sf.jasperreports.engine.util.JRLoader" %>

<%@ page import="net.sf.jasperreports.engine.JasperPrint" %>

<%@ page import="net.sf.jasperreports.engine.JRRuntimeException" %>

<%@ page import="net.sf.jasperreports.engine.JasperPrintManager" %>

<%@ page import="net.sf.jasperreports.engine.JasperReport" %>

<%@ page import="net.sf.jasperreports.engine.JRException" %>

<%@ page import="net.sf.jasperreports.engine.JasperFillManager" %>

<%@ page import="net.sf.jasperreports.engine.JRExporterParameter" %>

<%@ page import="java.math.BigDecimal" %>

<%@ page import="java.util.HashMap" %>

<%@ page import="java.util.Map" %>

<%@ page import="persistencia.Persistencia" %>

<%@ page import="java.sql.Connection" %>

<%@ page import="java.io.File" %>

<%@ page import="java.sql.Connection"%>

 

<%--

/**

* Método que se encarga de crear el reporte de un Equipo específico

*/

--%>

<%

String archivo = "reportes/";

int t = 1;

 

if ((t == 1) | (t == 22) | (t == 23))

archivo += "Computador.jasper";

else if ((t == 2) | (t == 3) | (t == 4) | (t == 5) | (t == 6) |

(t == 7) | (t == 8) | (t == 9) | (t == 10) | (t == 11))

archivo += "Red.jasper";

else if ((t == 12) | (t == 13))

archivo += "UPS_PT.jasper";

else if (t == 14)

archivo += "Bateria.jasper";

else if (t == 15)

archivo += "Cargador.jasper";

else if (t == 16)

archivo += "HandHeld.jasper";

else if (t == 17)

archivo += "Lector.jasper";

else if (t == 20)

archivo += "Base_Cargador.jasper";

 

File reportFile = new File(application.getRealPath(archivo));

 

if (!reportFile.exists())

throw new JRRuntimeException("Error al Cargar el reporte");

 

JasperReport jasperReport = (JasperReport)JRLoader.loadObject(

reportFile.getPath());

Map parametros = new HashMap();

int tipo_Equipo = 1;

String n_Equipo = "2";

String usr = "";

String pass = "";

String valor = "1";

String iva = "1";

Connection con = Persistencia.getInstance().demeConexion(usr, pass);

 

parametros.put("NUMERO" , n_Equipo);

parametros.put("tipo" , new BigDecimal(tipo_Equipo));

parametros.put("valor" , valor);

parametros.put("iva" , iva);

 

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,

parametros, con);

JRHtmlExporter exporter = new JRHtmlExporter();

 

JasperFillManager.fillReportToFile(reportFile.getPath(), parametros, con);

session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,

jasperPrint);

 

StringBuffer sbuffer = new StringBuffer();

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT , jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER , out);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,

"interfaz/image?image=");

exporter.exportReport();

%>

<html>

 

<script language="JavaScript" type="text/JavaScript">

 

<%--

/**

* Método que se encarga de hacer el direccionamiento al jsp indicado

*/

--%>

function menu(){

document.form.action = "menuPrincipal.jsp";

document.form.submit();

}

 

<%--

/**

* Método que se encarga de hacer el direccionamiento al Servlet de

* modificación

*/

--%>

function modificar(){

document.form.action = "/arte/hojadevida";

document.form.submit();

}

 

</script>

<body background="imagenes/BD21531_.jpg">

<form name="form" method="POST">

<%--

// Campo Oculto que contiene el Tipo de Equipo

--%>

<input type="hidden" name="tipo"

value="<%= request.getAttribute("tipo") %>">

 

<%--

// Campo Oculto que contiene el Número del Equipo

--%>

<input type="hidden" name="n_Equipo"

value="<%= request.getAttribute("numero") %>">

 

<%--

// Campo Oculto que contiene el tipo de Adquisición del Equipo

--%>

<input type="hidden" name="adquisicion"

value="<%= request.getAttribute("adquisicion") %>">

 

<%=sbuffer.toString()%> <%--// Mostrar el Reporte --%>

 

<br>

<p align="right">

<input type="button" value="Aceptar" onclick="javascript:menu();">

<input type="submit" value="Modificar" onclick="javascript:modificar();">  

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" hspace="0"

vspace="0" WIDTH = "140" HEIGHT = "32" codetype="application/java" align="middle">

<PARAM NAME = "code" VALUE = "Imprimir.class" >

<PARAM NAME = "codebase" VALUE = "applets" >

<PARAM NAME = "archive" VALUE = "jasperreports-1.2.5.jar" >

<PARAM NAME = "type" VALUE="application/x-java-applet;version=1.2.5">

<param name = "Tipo_Reporte" value = "Computador">

<EMBED type="application/x-java-applet;version=1.1.2"

CODE = "Imprimir.class" CODEBASE = "applets"

ARCHIVE = "jasperreports-1.2.5.jar" WIDTH = "140" hspace = "0"

vspace = "0" HEIGHT = "32"

pluginspage="http://java.sun.com/products/plugin/1.1.2/plugin-install.html">

</EMBED>

</object>

  

</p>

</form>

</body>

</html>

 

 

and this is the applet.java code:

 

/*

* Nombre de la clase: Imprimir

*

* Descripción: Applet que maneja la impresion de un Reporte

*

* Información de la versión: 1.0

*

* Fecha de creación: 18 de Septiembre de 2006

*

* Autor de la clase: Elsa Viviana Charry Lopez

*

* Fecha de modificación

*

* Autor de la modificación

*/

 

//==============================================================================

// BIBLIOTECAS REQUERIDAS

//==============================================================================

 

import javax.swing.JApplet;

import javax.swing.JButton;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.util.JRLoader;

import net.sf.jasperreports.engine.JasperPrintManager;

import java.io.StringWriter;

import java.io.PrintWriter;

import javax.swing.JOptionPane;

 

//==============================================================================

// CLASE Imprimir

//==============================================================================

 

public class Imprimir extends JApplet {

 

//------------------------------------------------------------------------------

// ATRIBUTOS DE INSTANCIA

//------------------------------------------------------------------------------

 

/* Tipo del Reporte a Imprimir */

String reporte;

 

//------------------------------------------------------------------------------

// METODOS CONSTRUCTORES

//------------------------------------------------------------------------------

 

/**

* Metodo Constructor de la Clase Imprimir que inicializa los componenetes

* que van a ir en el applet.

**/

public Imprimir() {

}

 

//------------------------------------------------------------------------------

// METODOS MODIFICADORES

//------------------------------------------------------------------------------

 

//Initialize the applet

public void init() {

reporte = "Computador";//"Computador";//

initComponents();

}

 

/**

* Método que Inicializa los componentes

*/

private void initComponents() {

JButton boton = new JButton();

 

boton.setText("Imprimir Reporte");

boton.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnPrintActionPerformed(evt);

}

});

 

getContentPane().add(boton);

}

 

/**

* Método que ejecuta la acción al presionar el botón de Impresión

* @param evt ActionEvent

*/

protected void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {

final String sourceFile = "C:\Documents and Settings\echarry.YCSA\" +

"jbproject\ARTE\arte\reportes\" + reporte + ".jrprint";

try {

Thread thread = new Thread(

new Runnable() {

public void run() {

try {

JasperPrint jasperPrint = (JasperPrint) JRLoader.

loadObject(sourceFile);

JasperPrintManager.printReport(jasperPrint, true);

} catch (Exception e) {

e.printStackTrace();

StringWriter swriter = new StringWriter();

PrintWriter pwriter = new PrintWriter(swriter);

 

e.printStackTrace(pwriter);

JOptionPane.showMessageDialog(null, swriter.toString());

}

}

}

);

 

thread.start();

} catch (Exception e) {

e.printStackTrace();

}

}

}

 

Please, if some one knows how can i solve this problem, i'll apreciate ur help!"!!!

 

Thanks a lot

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...