【问题标题】:Issue passing a image parameter from GWT/GXT to a Jasper report将图像参数从 GWT/GXT 传递到 Jasper 报告的问题
【发布时间】:2013-03-19 10:58:51
【问题描述】:

我正在尝试将一个简单的 .gif 图像从我的 GXT 应用程序提供给 jasper,以便它生成 Excel 报告。

我遇到的问题是,在尝试了多种选择之后,我总是在服务器端得到“java.lang.NullPointerException”。

我的 Jasper 报告中有以下代码:

    <parameter name="logo" class="java.lang.String"/>
...
        <image>
             <reportElement uuid="2f9765a4-f1dc-4af4-9ddf-fae1c7a3d152" x="110" y="0" width="206" height="40"/>
             <imageExpression><![CDATA[$P{logo}]]></imageExpression>
        </image>

还有 Java 代码:

 FileResolver fileResolver = new FileResolver() {

                 @Override
                 public File resolveFile(String fileName) {
                    URI uri;
                    try {
                      uri = new URI(this.getClass().getResource(fileName).getPath());
                      return new File(uri.getPath());
                    } catch (URISyntaxException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      return null;
                    }
                }
            };

            parameters.put("logo",  fileResolver.resolveFile("logo.GIF"));

我已经尝试了几种解决方案,但都遇到了问题。

logo.gif 放在已编译的 GWT 应用程序的 .war 文件夹中,其内容被归档为 .war 并部署在 Tomcat 7.0 服务器上。

希望有更多经验的人能帮助我,让我知道我做错了什么。

【问题讨论】:

  • URISyntaxException 被抛出了吗?
  • 当你说gif被放置在编译的GWT应用程序的war文件中时,它到底放在哪里?在客户端模块(包含所有生成的 JS 文件)或服务器模块(存在 servlet 类)中?请告诉GIF的路径

标签: java image gwt jasper-reports gxt


【解决方案1】:

FileResolver 对象应该像这样传递给 Jasper:

parameters.put("REPORT_FILE_RESOLVER", fileResolver);

你不应该自己打电话给fileResolver.resolveFile()FileResolver 方法的调用将由 JasperReports 自己完成。 This question 看起来很像你的(也许你已经看到了),它通过传递 FileResolver 作为参数来工作。

您可以在FileResolver here 上找到更多信息。此页面提到 FileResolver 自 JasperReports 5.0.1 起已弃用。如果您正在使用(或计划使用)5.0.1+,您应该尝试使用JasperResportsContextJasperReportsContext的使用示例可以参考this question

【讨论】:

  • 感谢您的回答,但徽标没有出现。 Jasper 代码中有什么我遗漏的吗?
  • 你在使用&lt;imageExpression class="java.lang.String"&gt;&lt;![CDATA["logo.gif"]]&gt;&lt;/imageExpression&gt;吗? (在这种情况下你不需要&lt;parameter name="logo" class="java.lang.String"/&gt;
  • 是的。我仍然在 uri = new URI(this.getClass().getResource(fileName).getPath()); 处收到空指针异常
  • 我会尝试通过在 IDE 中放置一个断点或打印出字符串 getClass().getResource(fileName).getPath() 来调试该行。这需要是文件的绝对路径。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多