• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Displaying image in JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a column of bytea in my postgres table storing image.  The contents of the image is like "0xFFD8FFE000104A46494600010101006000600000FFDB0043000302020302020303030304030304050805050404050A070706080C0A0C0C0B0A0B0B0D0E1210...". I migrated this image from SQL server.

How I can display this image in my jsp. I tried Base64 encoded, but it is not working. When I inspect the contents of img tag, it is like "\x4e554c4c...."

Please help me.  
 
Saloon Keeper
Posts: 6588
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The img tag should contain an URL where the browser can find the image, not the image data itself. You'll need a servlet that serves just the binary image data using a unique URL containing the ID of the image.
 
Ranjan Yengkhom
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same thing is working when I store a image with Base64 encoding.

my image tag contains like: <img  src="data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwX.." />

When I open the jsp, I bring the image as follows:

//ACTION CLASS
//set Photo working copy
BASE64Encoder base64Encoder = new BASE64Encoder();
StringBuilder imageString = new StringBuilder();
imageString.append("data:image/png;base64,");
imageString.append(new String(Base64.getDecoder().decode(rs.getBytes("Photo"))));
member.setPhoto(new String(imageString));

in jsp:

<img width="100" height="80" src="<s:property value='member.Photo'/>">

It works fine.
 
Tim Moores
Saloon Keeper
Posts: 6588
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, you're using a data: URL. OK, then: what format is the data that's stored in the DB? If it's ASCII and starts with "0x" then it's not in base64.
 
This is my favorite show. And this is my favorite tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic