anupp Posted August 5, 2010 Share Posted August 5, 2010 Hi, i want to generate pdf report but i m getting error net.sf.jasperreports.engine.JRException: Byte data not found at location : ../../Images/logo-agile-1.gif.If i remove image then pd report is generated fine. String reportPath = request.getSession().getServletContext().getResource("/reports/jasper").toString().substring(6); File file = new File(reportPath + "BrokerTurnover.jasper"); String jasperFile = file.getPath();but my LOGO is in image folder.so My jrxml is like that <image> <reportElement x="340" y="4" width="123" height="40"/> <imageExpression class="java.lang.String"><![CDATA["../../Images/logo-agile-1.gif"]]></imageExpression> </image>i m using servlet applicationprotected void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException { ServletOutputStream servletOutputStream =response.getOutputStream(); InputStream reportStream = getServletConfig().getServletContext() .getResourceAsStream("/reports/ParameterReport.jasper"); HashMap parameterMap = new HashMap(); parameterMap.put("paramName", "paramValue"); try { JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, new JREmptyDataSource()); response.setContentType("application/pdf"); servletOutputStream.flush(); servletOutputStream.close(); } catch (JRException e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain");response.getOutputStream().print(stringWriter.toString()); } } plz help me .its very urgent. Thanks Link to comment Share on other sites More sharing options...
pablodr Posted August 5, 2010 Share Posted August 5, 2010 Well, I had the same problem yesterday, and my solution was the next:I put the next code into my java reporter: String reportsDirPath =getServlet().getServletContext().getRealPath("/")+"path_to_my_report_folder" ; File reportsDir = new File(reportsDirPath); if (!reportsDir.exists()) { try { throw new FileNotFoundException(String.valueOf(reportsDir)); } catch (FileNotFoundException e) { e.printStackTrace(); mapping.findForward("/InternalError.do"); } } HashMap<String,Object> hm = new HashMap<String,Object>(); hm.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(reportsDir));Width this code I pass the path to my report template (the images are in the same directory) and then, when I compile the template, the location is correct.Then into jasperreport template, I only needs put the next to locate an image <image> <reportElement x="45" y="52" width="55" height="36"/> <imageExpression class="java.lang.String"><![CDATA["usc.jpeg"]]></imageExpression> </image> Link to comment Share on other sites More sharing options...
raulotalvaro_1 Posted March 3, 2014 Share Posted March 3, 2014 en modo de diseño le haces click a la imagen, le vuelves a cargar la ruta y listo Link to comment Share on other sites More sharing options...
segwatlhe Posted March 15, 2016 Share Posted March 15, 2016 Your solution worked for but with I had some modifications done to it. Link to comment Share on other sites More sharing options...
segwatlhe Posted March 15, 2016 Share Posted March 15, 2016 Your image expression should be something like this: <imageExpression><![CDATA[$P{reportLogo}]]></imageExpression>And you should use a HASHMAP to fetch the parameter value.String reportLogo = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/reports/Mytlogo.jpg");HashMap map = new HashMap();map.put("reportLogo", reportLogo); Lastly pass it in the JasperFillManager like this: JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, jrDataSource); Link to comment Share on other sites More sharing options...
satishmhiremath Posted December 1, 2016 Share Posted December 1, 2016 Error 500: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is net.sf.jasperreports.engine.JRException: Byte data not found at : ..//reports//images//adib-logo.gif The above error is fixed by using the imageExpression getClass().getResource("META-INF/resources/webjars/RBLTools/themes/default/images/RBL-LOGO.png").openStream() Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now