Exception in Jasper Report while integrating of Jasper report with Struts

Posted on 2009-05-18
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.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 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();




        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");



        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){




//        resultSet.close();

 //       statement.close();

//        ConnectionPool.closeConnection(connection);




     return mapping.getInputForward();




Open in new window

Question by:achitaley
LVL 92

Accepted Solution

objects earned 500 total points
ID: 24416994
>         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");


Author Comment

ID: 24570668
i try this but not working

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Understanding websocket example in spring 1 57
Exception after setting jdbc session management 2 52
maven example error 3 52
nextBoolean(double p) for Random class 3 35
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 This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

910 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

23 Experts available now in Live!

Get 1:1 Help Now