Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSF and the fly likes reading and display an image from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "reading and display an image from database" Watch "reading and display an image from database" New topic
Author

reading and display an image from database

akbar alkarij
Greenhorn

Joined: Sep 15, 2013
Posts: 1
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

Joined: Jun 25, 2001
Posts: 15952
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Enthu Tarun Singh
Greenhorn

Joined: Sep 23, 2013
Posts: 2

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.


http://www.sitenol.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: reading and display an image from database
 
Similar Threads
how to display an image using drawImage()
Getting a Image from a Blob using Servlet
Image Read from Blob
Upload Image in a JSP Page
create ImageIcon from bytes[], not from file