I have a bean with access to a image as byte[] here in the getImage method i convert a awt image to the byte array
public byte[] getImage() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageInByte = null;
try {
ImageIO.write( (BufferedImage)image, "jpg", baos );
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
return imageInByte;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return imageInByte;
}
I need to display the image with jsp within a table
like:
<table>
<c:forEach items="${beans}" var="bean">
<tr>
<td>${bean.name}</td>
<td>${bean.origin}</td>
<td>${bean.year}</td>
<td>${bean.number}</td>
<td>${bean.image}</td>
</tr>
</c:forEach>
Has it something to do with content type?
Create a img tag in your jsp file with src point to a servlet which will return the image byte array as a jpg image. You have to set correct mime type for the servlet output stream. One problem with this approach is that you have to save your image array in session for the servlet to pick it up.