Hi all,
I'm Quang, from Vietnam.
I use Jasper report on a web application (I used Tomcat web server). It's normal with exporting to Pdf file function, but viewing report with Jasper Viewer has a problem. When i exitted the Jasper Viewer, the Web server also shutted down. I didn't want that. Did I make some mistakes?
Here is my code:

public class JasperReportUtilWithoutDataSource {
 
 public static void viewReport(String jrxmlFile, Map<String, Object> parameters){
  try {
   JasperPrint jasperPrint = makeJasperPrint(jrxmlFile, parameters);
   JasperViewer.viewReport(jasperPrint);
  } catch (JRException e) {
   e.printStackTrace();
   System.exit(0);
  }
 }
 
 public static void exportToPdf(String jrxmlFile, Map<String, Object> parameters, String pdfOutFile) {
  try{
         JasperPrint jasperPrint = makeJasperPrint(jrxmlFile, parameters);
         JasperExportManager.exportReportToPdfFile(jasperPrint, pdfOutFile);
        } catch (JRException e) {
         System.out.println (e.getMessage());
         
        }catch (Exception e) {
         e.printStackTrace();
   System.exit(0);
        }
 }
 
 //-----------------------------------------------------------------------------------------

 private static JasperPrint makeJasperPrint(String jrxmlFile, Map<String, Object> parameters) throws JRException {
  JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFile);
  JasperReport jasperReport = JasperCompileManager.compileReport (jasperDesign);
  JasperPrint jasperPrint = JasperFillManager.fillReport(
    jasperReport, parameters, new JREmptyDataSource() );
  return jasperPrint;
 }
}

Hoping your reply soon.
Thank you very much.

Regards,

Quang

Reply via email to