0

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?

1 Answer 1

2

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 "";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Good grief, rookie mistake. Guess it was time to take a break

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.