Jump to content
We've recently updated our Privacy Statement, available here ×

Byte data not found at location : ../../Images/log


anupp

Recommended Posts

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 application

protected void doGet(HttpServletRequest request,HttpServletResponse
response) 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

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

 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

  • 3 years later...
  • 2 years later...

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

  • 8 months later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...