Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exception in Jasper Report while integrating of Jasper report with Struts

Posted on 2009-05-18
2
Medium Priority
?
1,658 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:Adwait Chitaley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1500 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");

0
 

Author Comment

by:Adwait Chitaley
ID: 24570668
i try this but not working
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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