java 使用ireport无法显示图片问题分析

我在ireport设计的时候,内嵌有网站logo图和一个条形码,结果调试的时候,图形都无法显示,查了网上资料

才知道是

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

需要把jasperPrint放入session,这样,ireport的图片显示服务器才能访问jasperPrint对象,显示出相应的图像出来

 

ireport显示外部图片的具体步骤:

1.在web-bin设置ireport图片显示服务:

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

2.设置ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTEsession

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

3.设置图片servlet服务的路径:

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

你可能感兴趣的:(IREPORT)