Solved

Exception in Jasper Report while integrating of Jasper report with Struts

Posted on 2009-05-18
2
1,601 Views
Last Modified: 2012-06-21
net.sf.jasperreports.engine.JRException: Failed to parse the xml document

 error in jasper report whille creating the jasper report using xml datasource .....

please help me out

or tell me how to retrive the xml file in my code ..


package net.ensode.jasperbook.struts;

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.HashMap;

import javax.servlet.ServletOutputStream;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import net.sf.jasperreports.engine.JasperCompileManager;

import net.sf.jasperreports.engine.JasperRunManager;
 

import net.sf.jasperreports.engine.data.JRXmlDataSource;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

 

public class GenerateReportAction extends Action

{

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception

{

     Connection connection=null;

     Statement statement=null;

     ResultSet resultSet=null;

//     ServletContext application=servlet.getServletContext();

//     DataSource datasource = (DataSource) application.getAttribute(Globals.DATA_SOURCE_KEY);

//     ConnectionPool.dsource=datasource;

     ServletOutputStream servletOutputStream =response.getOutputStream();

     response.setContentType("application/pdf"); 
 

     try{

         

        String query="select * from M55_USERS_NEW";

//         connection=ConnectionPool.openConnection();

         System.out.println("After load Driver========================");

//         statement = connection.createStatement();

//         resultSet = statement.executeQuery(query);

 //        JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(resultSet);

         System.out.println("Compiling report...");

         JasperCompileManager.compileReportToFile("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/reports/RemoteReport.jrxml");

         System.out.println("Compilation Succesfully----------------------->");
 

         System.out.println("Filling report...");

         InputStream reportStream=new FileInputStream("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperCompleteApplication/reports/RemoteReport.jasper");

         System.out.println("ReportStream---------->>>>>>>>>>>>>>>>"+reportStream.toString());

         System.out.println("Done!");
 

        JRXmlDataSource xmlDataSource = new JRXmlDataSource("userxml", "/userData/M55_USERS_NEW");
 

      
 

          System.out.println("After XMl  xmlDataSource read------->");

         JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap(),xmlDataSource);

  

        }catch(Exception e){

            e.printStackTrace();

        }

     finally{

//        resultSet.close();

 //       statement.close();

//        ConnectionPool.closeConnection(connection);

        servletOutputStream.flush();

        servletOutputStream.close();

     }

     return mapping.getInputForward();

    }

 

}

Open in new window

0
Comment
Question by:achitaley
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
>         JRXmlDataSource xmlDataSource = new JRXmlDataSource("userxml", "/userData/M55_USERS_NEW");

need to pass it a file

        JRXmlDataSource xmlDataSource = new JRXmlDataSource(new File("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperCompleteApplication/reports/RemoteReport.jasper"), "/userData/M55_USERS_NEW");

0
 

Author Comment

by:achitaley
Comment Utility
i try this but not working
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now