html export + image impossible

1

 

Hi,

using jasperreports 4.8 with JDeveloper 11.1.1.5 and weblogic 10.3.5.0 I lost my mind over this, since I've done this sucessfully using jasperreports 3.7. with Jdeveloper 10.1.3.4 and OAS 10.1.3.4.1, but now I simply cannot make it work. I've googled for hours and nothing helped me.
 
web.xml
 
   
            ImageServlet
            net.sf.jasperreports.j2ee.servlets.ImageServlet
   
   
            ImageServlet
            /image
   
 
servlet.java (based on webapp demo - HtmlServlet, same goes for XhtmlServlet does not work)
 
            PrintWriter out = response.getWriter();
            
            File sourceFile = new File("/test.jasper");
            jReport = (JasperReport)JRLoader.loadObject(sourceFile);
 
            OracleConnection conn = getDBConnection("STRKZR");
 
            HashMap paramNameValues = new HashMap();
            jPrint = JasperFillManager.fillReport(jReport, paramNameValues, conn);
            
            JRHtmlExporter exporter = new JRHtmlExporter();
            request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jPrint);
            
            exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE); //regardless if this is true or false images do not show up
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
            exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "http://127.0.0.1:7101/Portal-ViewController-context-root/faces/image?image="); // hardcoded url to ImageServlet
            
            exporter.exportReport();
 
 
When I look at the html source I can clearly see the src for image and it's correct:
 
 
I can copy paste the image src into new browser tab and it is displayed correctly. 
 
What could be the solution for this? Please help I'm out of ideas.
 
 
 
 
Solved:
 
 
            request.getSession().setAttribute(net.sf.jasperreports.j2ee.servlets.ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jPrint);
            exporter.setParameter(JRExporterParameter.JASPER_PRINT,jPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getWriter());
            exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../image?image="); //this is the line that was worng
            exporter.exportReport();
 

 

 

thundric's picture
Joined: Feb 14 2008 - 10:37pm
Last seen: 5 years 11 months ago
Is realy exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE) required options to show images in html? It's very strange. P.S. I am use this options in all applications. But I'm very surprised
sanbez - 8 years 4 months ago
I've tried with and without exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE) and I can confirm that images are displayed correctly in both cases. This is not critical. My problem was only the line: exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"../image?image="); Just in case if someone wonders how to stop getting images from cache this can be used: exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"../image?"+ "time=" + System.currentTimeMillis() + "&image="); Hope it helps.
thundric - 8 years 4 months ago
Thanks for explanation. Im am knows about correct value parameter JRHtmlExporterParameter.IMAGES_URI = "image?image". But you found the solution before I see your question. With best regards. Alexander
sanbez - 8 years 4 months ago

0 Answers:

No answers yet
Feedback