javabridge and jasperreports: jasperViewer Problem

General discussion forum for the Zend Server
Post Reply
vaa03
Posts: 20
Joined: Sun Apr 04, 2010 11:57 pm

javabridge and jasperreports: jasperViewer Problem

Post by vaa03 » Thu May 06, 2010 2:09 pm

Hi,
i'm using jasperreports with javabridge;

i can't use net.sf.jasperreports.view.JasperViewer for the preview into the browser, but if i use JasperExportManager to save the pdf to file, it's work fine. (see the last comment line);

i don't know cause of this strange behavior, when i try to run the page, the browser shows me a blank page without any errors but no preview window is opened!

Can anyone help me?

thank you very much,
Mirco.

Code: Select all

$reportsPath 	= dirname(__FILE__) . DIRECTORY_SEPARATOR . 'reports' ;			
	$reportFileName 	= "test";
	
	$objJcm = new Java("net.sf.jasperreports.engine.JasperCompileManager");	
	$objReport = $objJcm->compileReport($reportsPath . DIRECTORY_SEPARATOR . $reportFileName . ".jrxml");
	
	$fillManager = new Java("net.sf.jasperreports.engine.JasperFillManager");
	$params = new Java("java.util.HashMap");
	
	$jasperPrint 	= new Java("net.sf.jasperreports.engine.JasperPrint");
	$viewer			= new Java("net.sf.jasperreports.view.JasperViewer");
	
	$emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");	
	$jasperPrint = $fillManager->fillReport($objReport, $params, $emptyDataSource);
		
	try {		
		$viewer->viewReport($jasperPrint);		
	}
	catch(Exception $e){
		var_dump($e);
	}
	
	/* EXPORT TO FILE	
	$exportManager = new Java("net.sf.jasperreports.engine.JasperExportManager");
	$outputPath = realpath(".")."\\"."output.pdf";		
	$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
	*/

leslie26
Posts: 4
Joined: Thu Apr 29, 2010 7:04 pm

Re: javabridge and jasperreports: jasperViewer Problem

Post by leslie26 » Mon May 10, 2010 7:03 pm

Brother you configure tha file java_bridge_server?

When install zend how custom I checked java bridge. But before of install have configure java_bridge_server.ini
The my have configure way:
[JAVA_BRIDGE_SERVER]
CLASSPATH="C:\Zend\ZendServer\bin\javamw.jar;.;C:\Zend\ZendServer\bin\JasperReports\commons-beanutils-1.8.2.jar;.;C:\Zend\ZendServer\bin\JasperReports\commons-collections-3.2.1.jar;.;C:\Zend\ZendServer\bin\JasperReports\commons-javaflow-20060411.jar;.;C:\Zend\ZendServer\bin\JasperReports\commons-logging-1.1.jar;.;C:\Zend\ZendServer\bin\JasperReports\commons-digester-1.7.jar;.;C:\Zend\ZendServer\bin\JasperReports\jdt-compiler-3.1.1.jar;.;C:\Zend\ZendServer\bin\JasperReports\com-jaspersoft-ireport.jar;.;C:\Zend\ZendServer\bin\JasperReports\com-jaspersoft-ireport-jasperserver.jar;.;C:\Zend\ZendServer\bin\JasperReports\jasperreports-3.7.2.jar;.;C:\Zend\ZendServer\bin\JasperReports\jasperreports-extensions-3.5.3.jar;.;C:\Zend\ZendServer\bin\JasperReports\groovy-all-1.5.5.jar;.;C:\Zend\ZendServer\bin\JasperReports\conexao.jar;.;C:\Zend\ZendServer\bin\JasperReports\iText-2.1.7.jar;.;C:\Zend\ZendServer\bin\JasperReports\poi-3.5-FINAL-20090928.jar;.;C:\Zend\ZendServer\bin\JasperReports\sqljdbc4.jar;.;C:\Zend\ZendServer\bin\JasperReports\postgresql-8.3-603.jdbc3.jar;.;C:\Zend\ZendServer\bin\JasperReports\mysql-connector-java-5.1.6-bin.jar;.;.;C:\Zend\ZendServer\bin\JasperReports\barbecue-1.5-beta1.jar;.;.;C:\Zend\ZendServer\bin\JasperReports\barcode4j-2.0.jar;.;.;C:\Zend\ZendServer\bin\JasperReports\jfreechart-1.0.12.jar;."
Then restarted the PC and put the report to generate static, because when he tried to SGDB was blank. Then he successfully led the report found that the problem was to connect to the database because the password used many special characters, so I put it simple and had a good report.
Test report without database connection:

Code: Select all

<?
$compileManager = new Java("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport(realpath("test.jrxml"));

$fillManager = new Java("net.sf.jasperreports.engine.JasperFillManager");

$params = new Java("java.util.HashMap");
$params->put("nome", "wgs");

$emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");
$jasperPrint = $fillManager->fillReport($report, $params, $emptyDataSource);

$outputPath = realpath(".")."/"."output.pdf";

$exportManager = new Java("net.sf.jasperreports.engine.JasperExportManager");
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

header("Content-type: application/pdf");
readfile($outputPath);
?>
now with database connection:

Code: Select all

<?

$login_host = "";
$login_password = utf8_decode("");
$login_database = "";
$login_username = "";

$Connection    = new Java("java.sql.Connection");
$DriverManager = new Java("java.sql.DriverManager");
$SQLException  = new Java("java.sql.SQLException");

try
{
    $conexao = null;
    $conn = new Java("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    $url = 'jdbc:sqlserver://'.$login_host.';databaseName='.$login_database;
    $conexao = $DriverManager->getConnection($url,$login_username,$login_password);
}
catch(Exception $e)
{
    echo "<pre>";
    print_r($Connection->ClassNotFoundException->getMessage());
    print_r($SQLException->SQLException->getMessage());
    echo "</pre>";
}

$compileManager = new Java("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport(realpath("test.jrxml"));

$fillManager = new Java("net.sf.jasperreports.engine.JasperFillManager");

$params = new Java("java.util.HashMap");
$params->put("nome", "wgs");

$jasperPrint = $fillManager->fillReport($report, $params, $conexao);

$outputPath = realpath(".")."/"."output.pdf";

$exportManager = new Java("net.sf.jasperreports.engine.JasperExportManager");
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

header("Content-type: application/pdf");
readfile($outputPath);
?>

Post Reply