Jump to content

Cannot get images to display in HTML report


toltsch

Recommended Posts

I'm using the JRHtmlExporter to create an html report.

 

The report displays in the browser but the images are not displayed.

 

The image tag looks like this in the html:

 

img src="image?image=img_0_0_2"

 

When I use the isLazy attribute the image src is empty

 

img src=""

 

I'm using the java.net.URL in the report.

 

When I use the ireport tool and test using this URL

it works:

 

http://localhost:9080/CWCollaborateAppWeb/cdc/images/cwilogo.jpg

 

My code looks like this:

 

JRHtmlExporter exporter = new JRHtmlExporter();

 

HashMap imagesMap = new HashMap();

 

request.getSession().setAttribute("IMAGES_MAP", imagesMap);

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);

exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER,"<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body>");

exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);

 

exporter.exportReport();

 

I also added these lines to my web.xml file:

 

<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>image</url-pattern>

</servlet-mapping>

 

Any ideas what I'm missing?

 

Regards,

 

Tim

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...