Jump to content

Image hard-coded to img_0_1_34 in HTML!


AnjumAbbas

Recommended Posts

Hi, 

I'm got a jrxml designed in ireport. It has a single image 'VW-logo-34px.jpg' defined in the report as $P{imagePath} + "VW-logo-34px.jpg". When I export to pdf and excel I can see the image clearly however it does not show when I export to xhtml.

I have followed the example in demo/samples/webapp on adding an image servlet.

This is what I have added to my web.xml

<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
</servlet>
 
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/servlets/image</url-pattern>
</servlet-mapping>
 
Here is the code which produces the jasperprint and does the export I have configured the image servlet in this way
                   JRXhtmlExporter htmlExporter = new JRXhtmlExporter();
                    htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                    htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");
                   htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, getImageMap());          
                    htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getWriter());
                    htmlExporter.exportReport();
 
However after exporting the resulting html page shows the following:
<img style="position: absolute; height: 56px; top: 0px; left: 0px;" alt="" src="image?image=img_0_1_34"/>
 
Why is it hardcoding img_0_1_34 as the name of the image and not putting in the correct image name i.e. VW-logo-34px.jpg?!
 
Someone please help as I've been searching for an answer on the forums for a day now and having tried everything suggested and following the sample demo. 
Thanks
 
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Okay I solved this by adding the following lines to the code which exports to html file.

htmlExporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, request.getSession().getServletContext().getRealPath("/jsp/images/"));
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,getImageURI());
 
I found the solution right at the bottom of this thread:
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...