Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jasper Problem

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, I'm having a problem getting Jasper to work correctly.. I always get an Error Loading Object From InputStream exception on the JasperRunManager line...

my code is as follows..

try {
Connection con = com.dbws.king.DBConnection.getJNDIConnection();
response.setHeader("Cache-Control", "max-age=30");
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=reportpdf.pdf");
ServletContext sc = getServletContext();
InputStream is = getServletContext().getResourceAsStream("WEB-INF/Reports/test2.jasper");
Map parameters = new HashMap();
JasperRunManager.runReportToPdfStream( is,response.getOutputStream(),parameters,con);
} catch(Exception e) {System.out.println(e.toString());}

whilst debugging I can confirm that is not null so the path to the file is correct and is being picked up, so i'm not sure why it would be having a problem with the InputStream. The .jasper file I created in iReport.

Any thoughts appreciated.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the problem eventually.. so for the benefit of others who may run into this....

It was all down to the version of my jasper jar. I download jasper 0.6.6 and was using iReport which comes with version 0.6.4. The compiled .jasper file from iReport being version 0.6.4 was causing the problem so I copied the 0.6.4 jar from my jasper sdk into my tomcat common/lib directory and removed the 0.6.4 jar and all problems vanished.

Rgds,

Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic