Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading and display an image from database

 
akbar alkarij
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to display a Image read from the server as byte[]

I read the image in the entity class as byte[] and i want to create a image and save it in server and while clicking a button in jsf page i want to load the image to p:graphicImage
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Akbar!

Web images are always fetched via separate URLs. That's what the HTML image tag and its corresponding h:graphicImage tag do, is define the URL from which the image is going to be retrieved.

If your image is already stored in a supported binary image format (such as jpg or gif) within the WAR, all that's needed is to construct a URL that references this image resource.

If you are pulling the image from a BLOB in a database or dynamically constructing the image - for example, as a graph - then you will have to construct a temporary image resource and provide a URL mechanism that retrieves the content of that image.

JSF itself will not be aware of which of the above you are using, since in both cases, a URL is the means of access. Merely that in one case you are using the webapp server's default URL resolution functions and in the other, you're providing a URL resolution function of your own.
 
Enthu Tarun Singh
Greenhorn
Posts: 2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with the above comment and doing so will increase performance. If you are intended to load from Data base then you have to read BLOB from data base using InputReader, BufferReder and set that value in the <h:graphicImage />tag of JSF.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic