Jump to content
Changes to the Jaspersoft community edition download ×

Problem to view a report into a JSP


2004 IR Help

Recommended Posts

By: AleXXandra - alexxandra

Problem to view a report into a JSP

2005-06-07 01:37

Hi, I wrote the following code for a JSP Taglib, to generate a PDF from a .jasper file. No problem with the generation of a PDF file, unable to view it in streaming instead. Can you help me?

Thank you in advantage,

AleX

 

 

package com.tag;

 

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

 

import net.sf.jasperreports.engine.*;

import net.sf.jasperreports.engine.export.*;

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

import net.sf.jasperreports.view.*;

 

import java.sql.*;

import org.apache.commons.logging.*;

import java.io.*;

import java.util.*;

 

 

public class GeneratePDF extends TagSupport

{

private String sourceFileName = "C:\default.jasper";

private String destinationFileName = "C:\default.pdf";

 

 

public void setSourceFileName(String sourceFileName)

{

this.sourceFileName = sourceFileName;

 

}

public void setDestinationFileName(String destinationFileName)

{

this.destinationFileName = destinationFileName;

}

 

 

public int doStartTag()

{

return SKIP_BODY;

}

 

public int doEndTag()

{

try

{

 

//Passaggio parametri da passare al jasper.

Map parameters = new HashMap();

parameters.put("param1", new Integer(1));

 

 

//Preparazione del file da stampare (in questa fase si esegue la query e si inseriscono

//i valori estratti dalla query)

JasperPrint jasperPrint=JasperFillManager.fillReport(sourceFileName, parameters, getConnection());

 

 

 

//Creazione del file PDF

JasperExportManager.exportReportToPdfFile(jasperPrint, destinationFileName);

 

 

//Streaming a video del PDF

pageContext.getOut().print(JasperExportManager.exportReportToPdf(jasperPrint));

 

}

 

 

catch(Exception e)

{}

 

 

return EVAL_PAGE;

}

 

 

/**Metodo per creare la connessione al DB*/

private static Connection getConnection() throws ClassNotFoundException, SQLException {

//Change these settings according to your local configuration

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

String connectString = "jdbc:odbc:gecoware";

String user = "admin";

String password = "password";

 

Class.forName(driver);

Connection conn = DriverManager.getConnection(connectString, user, password);

return conn;

}

 

 

}

 

 

 

 

 

By: Bogdan - cecenu

RE: Problem to view a report into a JSP

2005-06-07 04:55

Hello. I have posted a replay at your previous message on this forum with the same subject. It didn't helpt you?

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...