I have complex Java Object List contains a byte array as image format retrieved from DB. There are file name, file type and file data in byte array format etc. in the POJO. byte array is about 20k in length. I can display it in JSP by javascript as:
for(var i in data){
var imgelement = document.createElement("IMG");
imgelement.id=data[i].fileId;
imgelement.src = "data:"+data[i].fileType+";base64,"+data[i].thumbnail;
}
This will display IMG properly.
But when I try to put it in my plain JSP by using jstl foreach function to iterate my POJO list, I never get my image display.
<c:forEach items="${searchResult}" var="current" varStatus="i">
<c:choose>
<c:when test="${(i.count) % 2 == 0}">
<c:set var="rowclass" value="rowtwo" />
</c:when>
<c:otherwise>
<c:set var="rowclass" value="rowone" />
</c:otherwise>
</c:choose>
<tr class="${rowclass}">
<td nowrap="nowrap" class="tabletd"> <img src="data:${current.miniFile.fileTyle};base64,<c:out value='${current.miniFile.thumbnail}'/>"/> </td>
<td nowrap="nowrap" class="tabletd"> ${current.site.siteName} </td>
<td nowrap="nowrap" class="tabletd"> ${current.distance} </td>
<td nowrap="nowrap" class="tabletd"> ${current.site.siteAccessby} </td>
<td nowrap="nowrap" class="tabletd"> ${current.site.siteAddressFormated} </td>
</tr>
</c:forEach>
There is the out put in my html page shows, the src as a byte array:
<img src="data:image/jpeg;base64,[B@2e29c573">
Any idea? Advice please!
Edit
I am trying to use Java 8 Java.util.Base64's function by jsp:useBean to do the byte array convert, but it is still not works for me.
Other question, How I can use jsp:useBean to do it? as the variable is jstl variable. i.e. I need to use jsp:usedBean function to handle jstl local variable.
code like:
<tr class="${rowclass}">
<jsp:useBean id="obj" class="java.util.Base64"/>
<jsp:setProperty name="imageStr" property="String" value="${current.miniFile.thumbnail}"/>
<td nowrap="nowrap" class="tabletd"> <img src="data:${current.miniFile.fileTyle};base64,<c:out value='${current.miniFile.thumbnail}'/>"/> </td>
I don't have experience to handle jstl variable by using jsp:useBean, who have such experience, please share to me! Appreciated!
EDIT AGAIN
There is an example to do the Date type charge by using jsp:useBean