图像未以ireport html格式显示

时间:2011-07-26 09:33:03

标签: ireport

我试了很长时间:

我正在使用iReport设计器创建报告。因为它以各种格式(PDF,Excel,RTF)显示图像,但是当我试图在JSP中以HTML格式显示时,图像不显示。我想做什么来解决这个问题。我正在尝试这个很长一段时间。有谁可以帮助我?

提前致谢。

3 个答案:

答案 0 :(得分:2)

要注意的一件事是,如果HTML中有两个重叠的控件,则不会显示其中一个控件。确保没有其他控件与图像控件重叠。

我以前在文本字段中遇到过这个问题。

答案 1 :(得分:1)

对于您的图片,请尝试表达式类

'net.sf.jasperreports.engine.JRRenderable'

以及类似于图像表达式的内容:

net.sf.jasperreports.engine.JRImageRenderer.getInstance("image-dir/report-logo.gif")

在jasper报告文件(例如myreport.jrxml)中,图像的表达式如下所示:

<image scaleImage="Clip" isUsingCache="false">
    <reportElement key="image-1" x="0" y="0" width="65" height="47"/>
    <imageExpression class="net.sf.jasperreports.engine.JRRenderable"><![CDATA[net.sf.jasperreports.engine.JRImageRenderer.getInstance(image-dir"/report-logo.gif")]]></imageExpression>
</image>

对于Html报告,图像servlet可能很有用,可以在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>/report/image</url-pattern>
</servlet-mapping>

Java / Spring代码执行报告,其中a.o。为图像servlet设置图像uri:

public ModelAndView createReport(HttpSession session, String reportName, String format) {

ApplicationContext context = this.getApplicationContext();
JasperReportsMultiFormatView report = new CollegeJasperReportsMultiFormatView(session); 
report.setUrl("/WEB-INF/reports/jasper/" + reportName + ".jasper");

Map<String, Object> model = getModel();
model.put("format", format);

Map parameters = new HashMap();
report.setExporterParameters(parameters);
parameters.put(JRExporterParameter.CHARACTER_ENCODING, "UTF8");
parameters.put(JRHtmlExporterParameter.IMAGES_URI, "../report/image?image=");
parameters.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);

Properties contentDispositionMappings = new Properties();;
contentDispositionMappings.put(format, "inline; filename=report." + format);
report.setContentDispositionMappings(contentDispositionMappings);

report.setApplicationContext(context);      // this will convert the export parameters, so has to be called after setExportParameters()
return new ModelAndView(report, model);
}

答案 2 :(得分:1)

这是你可以生成HTML报告并指向更新的JasperReports库的图像servlet的方式(我使用的是6.1.0),因为许多旧函数已被弃用:

var done = 0;

var a_1;
var a_2;
var b_1;
var b_2;

users.findOne({username: game.teamA_player1}, function(err, usera1){
    if(usera1)
        a_1 = usera1.rating;
    done += 1;
});
users.findOne({username: game.teamA_player2}, function(err, usera2){
    if(usera2)
        a_2 = usera2.rating;
    done += 1;
});
users.findOne({username: game.teamB_player1}, function(err, userb1){
    if(userb1)
        b_1 = userb1.rating;
    done += 1;
});
users.findOne({username: game.teamB_player2}, function(err, userb2){
    if(userb2)
        b_2 = userb2.rating;
    done += 1;
});

//Keep looping on deasync until we find all 4
require('deasync').loopWhile(function(){return (done!=4);});

if(a_1 == undefined || a_2 == undefined || b_1 == undefined || b_2 == undefined){
    // could not find a user probably
    log('Value undefined, error');
    return;
}