0

I am trying to show the image that I have took from my database, but when the page opens it doesn't show the image. I have taken the image from the database which is saved as a blob, turned into byte[] and then turned it into an image icon. Then sending it to the jsp via model.addAttribute. Here is the code where I am getting the blob and converting: This is my controller method

if(post.getImage() != null) {
        Blob blob = post.getImage();
        ImageIcon ii=new ImageIcon(blob.getBytes(1, (int) blob.length()),"description");
        System.out.println("shalom " + ii);
        model.addAttribute("img", ii);
    }

And this is where I am trying to use the image

<img src="<c:out value="${img}"/>" width="100" height="100"></img>

If there's any ideas I would be very appreciative. Cheers Jim :)

  • 1
    What actual output do you get in your page for that `img` tag? What does the `src` attribute of an `img` tag need to be? – tgdavies Feb 23 '21 at 00:11
  • I just get a white box (the css styling) I would upload a random picture say of a can of fanta and the white box is all I get. The src tag is being set by the model.addAttribute. So this would be the image icon of the image created. –  Feb 23 '21 at 00:32
  • I mean: what is the page source generated for that `img` tag? – tgdavies Feb 23 '21 at 00:40
  • `` I am guessing this is the name of the file rather than the actual image. –  Feb 23 '21 at 00:44

0 Answers0