Reputation: 11309
I have the following in a JSP with Spring:
<img alt="Embedded Image" src="data:image/png;base64,${item.imageDataBase64}"/>
I have a debug statement in the getImageDataBase64
method in the bean and the message gets printed in the Tomcat logs properly, the base 64 data is encoded there.
However, it does not display on my JSP. I have tried displaying the plain data in <pre>
tags, but it is always blank.
If I just do ${item.imageData}
it displays the byte array data.
Here is the relevant Java code:
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;
}
Any ideas why this would happen?
Upvotes: 0
Views: 74
Reputation: 24590
From what I see your code works as expected and returns an empty string.
In your getImageDataBase64
method try replacing this:
if (imageData != null) {
return "";
}
with this:
if (imageData == null) {
return "";
}
Upvotes: 2