Search code examples
javahtmlimageimageicon

Java - Insert Byte Array/ImageIcon directly into HTML


I'm trying to take a byte array directly from the DB and put it into a tooltip that takes HTML. This is for consistency as text needs to be included that will match the other text-only tooltips.

I'm ideally trying to bypass the step of saving the image to a file before loading it into an img src tag. Is there a way to load a byte array (could easily be converted into Image or ImageIcon beforehand) straight into HTML?


Solution

  • Make an image-serving servlet, map it to an appropriate URL and just dump the image data from the database.

    Edit: by the way you can have the browser cache the images with this approach, but you to do it manually.