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

russ_87

Members
  • Posts

    6
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Everything posted by russ_87

  1. Ok, so I think I'm on the path to a solution, but I'm still not sure on how to correct it. I was reading up on the subject here: http://www.ibm.com/developerworks/websphere/library/techarticles/0411_olivieri/0411_olivieri.html In the article, this mentions how to add images to your report. The sample code and this line: "In this example, the <imageExpression> sub-element uses a java.io.File object to locate the image file that needs to be loaded." makes me think that the problem is how I'm adding the images to the report design. I'm using java code to do it, and here is the code that I use to add an image. Now, what I'm thinking is that the problem is caused by the fact that I'm setting the expression to a string, when it needs to be a file in order for it to be mapped properly. Any thoughts as to whether or not I'm on the right track? I can't find a way to set the expression to the File class and still have the report compile properly. Code: JRDesignImage image = new JRDesignImage(jDesign); JRDesignExpression expression = new JRDesignExpression(); image = new JRDesignImage(jDesign); image.setVerticalAlignment(JRDesignImage.VERTICAL_ALIGN_MIDDLE); image.setY(imageDesignY); image.setHeight(350); image.setWidth(500); image.setHorizontalAlignment(JRDesignImage.HORIZONTAL_ALIGN_CENTER); image.setScaleImage(JRDesignImage.STRETCH_TYPE_RELATIVE_TO_BAND_HEIGHT); image.setLazy(true); expression.setValueClass(java.lang.String.class); expression.setText(fileURL); image.setExpression(expression);
  2. This is only going to highlight how ignorant I've been of the process, but actually, that was what I was trying to do. When I originally started working with JasperReports, for a school project, we were generating the reports and saving them to the hard disk. I was able to successfully get them to save the reports, charts included, when I was doing it that way. As an extension of the project, we've been converting it to a web application. This includes delivering the reports directly to the browser, either as PDF or HTML. The PDF reports work fine, I'm able to get them to display in the browser properly, chart images included. However when I follow the same steps for HTML, the problem I described above persists. The URL for the html page is http://localhost:8080/STATWeb/STAT/HtmlServlet It's on that html page that the chart shows as a broken image, and when I right click on it and select "Copy Image Location" it shows as the path to my local disk. Obviously I'm not doing something correctly when trying to have the HTML exporter access the images, but I'd appreciate a nod in the right direction.
  3. Well, it could be that the problem is caused by the relative path, but I'm not sure how to fix it. In my report, I copied the image location, which is saved on my hard drive. So the URL for the image isomething like C:\Users\Reports\Images. If I pasted that into my browser, it added the "file:///" prefix to the URL, and the image loaded fine. From the sounds of it, the problem could be caused by how I'm saving my chart files. When I generate the reports and charts, they are saved to another location on my local machine. Would this stop the HTML exporter from being able to access them?
  4. Sorry to jump in on this topic, but did the OP ever find a solution? I'm having the exact same issue. I've copied my code below, but it is the same as the what was posted, and nearly identical to the sample HTML servlet provided in the demo. Also, in the html page that gets displayed, if I copy the image location of the broken image, the output I paste is the correct path to the image file. Exporter parameters: List jasperPrintList = BaseHttpServlet.getJasperPrintList(request); if (jasperPrintList == null) { throw new ServletException("No JasperPrint documents found on the HTTP session."); } JasperPrint jasperPrint = (JasperPrint)jasperPrintList.get(0); JRHtmlExporter exporter = new JRHtmlExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); Web XML: <servlet> <servlet-name>image</servlet-name> <servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>image</servlet-name> <url-pattern>/image</url-pattern> </servlet-mapping>
  5. I just noticed that this isn't even a fair representation of my problem. In the above, you can see I left out the escape character for the slashes in the file path, and the error backs that up. Let me try again. This is what the iReport designer gives me for the expression: <imageExpression class="java.lang.String"><![CDATA["D:\\My Documents\\NetBeansProjects\\STAT 0.1\\build\\Images\\logo.jpg"]]></imageExpression> My code: expression.setText("![CDATA[\"D:\\\\My Documents\\\\NetBeansProjects\\\\STAT 0.1\\\\build\\\\Images\\\\logo.jpg\"]]"); The error: D:\My Documents\NetBeansProjects\STAT 0.1\StudentReport_1268185816578_660519.java:201: illegal start of expression value = (java.lang.String)(![CDATA["D:\\My Documents\\NetBeansProjects\\STAT 0.1\\build\\Images\\logo.jpg"]]); //$JR_EXPR_ID=12$ There is also an arrow that points to the opening square bracket after the exclamation point. Thanks again for any help. Really I just need to know how I can properly set the image expression in Java.
  6. Hi All, I'm fairly new to Jasper Reports, and have been trying to create my reports using only Java code, basing it off of the noXMLDesign App that comes with the samples. One thing that isn't included, is how to add images to the report. I've added the following (see code), but when the report tries to compile, I get the following error: "illegal start of expression value = (java.lang.String)(![CDATA["D:My DocumentsNetBeansProjectsSTAT 0.1buildImageslogo.jpg"]]); //$JR_EXPR_ID=12$" Now, my question is, how do I properly set the expression for the image in Java? The expression that I wrote is what the iReport builder gave me when I added an image to the report, I just added the escape characters for quotations. Appreciate any help. Regards, Russell Code: Post Edited by russ_87 at 03/08/2010 21:40
×
×
  • Create New...