【问题标题】:Spring MVC JSP not showing output properlySpring MVC JSP 未正确显示输出
【发布时间】:2014-05-22 16:53:54
【问题描述】:

我在带有 Spring 的 JSP 中有以下内容:

<img alt="Embedded Image" src="data:image/png;base64,${item.imageDataBase64}"/>

我在 bean 的 getImageDataBase64 方法中有一个调试语句,消息正确打印在 Tomcat 日志中,base 64 数据在那里编码。

但是,它没有显示在我的 JSP 上。我尝试在<pre> 标签中显示纯数据,但它始终为空白。

如果我只是做${item.imageData},它会显示字节数组数据。

这里是相关的Java代码:

public String getImageDataBase64() {
    L.debug("Sending base 64 data: {}", org.apache.commons.codec.binary.Base64
                                        .encodeBase64String(imageData));
    if (imageData != null) {
        return "";
    }
    return org.apache.commons.codec.binary.Base64
           .encodeBase64String(imageData);
}

/**
* @return the imageData
*/
public byte[] getImageData() {
    return imageData;
}

任何想法为什么会发生这种情况?

【问题讨论】:

    标签: spring jsp model-view-controller


    【解决方案1】:

    据我所知,您的代码按预期工作并返回一个空字符串。

    在您的 getImageDataBase64 方法中尝试替换它:

    if (imageData != null) {
        return "";
    }
    

    用这个:

    if (imageData == null) {
        return "";
    }
    

    【讨论】:

    • 天哪,菜鸟的错误。猜猜是时候休息了
    猜你喜欢
    • 2016-08-21
    • 2019-01-05
    • 2014-01-24
    • 2013-05-15
    • 2023-03-26
    • 1970-01-01
    • 2013-05-11
    • 1970-01-01
    • 2021-10-01
    相关资源
    最近更新 更多