Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Displaying BLOB image in a jsp page through struts.

  Asked By: Ketan    Date: Jun 24    Category: Java    Views: 7263

I am trying to display an image in a jsp page which is stored as a blob in the oracle table.
I wrote a stored procedure to get all the images for a particular id.

and in the servlet(action), I wrote the following:


ResultSet rsImg = verServ.getImages(EtaId,conn);
VDTO vadto = new VDTO();
Blob Imgs = rsImg.getBlob("IMG");
byte ImgData[] = Imgs.getBytes(1,(int)Imgs.length());
request.setAttribute("images", ImagesLst);

I am passing the Arraylist as a request Attribute to the jsp page, from where the Img tag calls a servlet passing the byte[].

Although I use Struts Framework, I would use jsp/struts tags for displaying my image(s) in jsp

Please guide me to write tags in jsp/struts for displaying my images.



2 Answers Found

Answer #1    Answered By: May Hansen     Answered On: Jun 24

in order to display  the image  loaded, you have to store them in a scope larger than request
when request  is ended and html page  is builded and sended to browser, browser sends another requests to server for each img  tag in html page.
so you have to :
1) store image in an scope broader than request like session
2) write  some tags  that reads data from them and writes them to jsp  page
there is another solution

when you are making html page just put a refrence of the picture in page in IMG tag  and lazy load pictures at time it is needed to be rendered, for example put entity name, and primary key of picture in picture name, and write a servlet  that using these two fetches pictures from database and displays it.

some modern frameworks like seam have special soloutions for rendering pictures.

Answer #2    Answered By: Abana Cohen     Answered On: Jun 24
Didn't find what you were looking for? Find more on Displaying BLOB image in a jsp page through struts. Or get search suggestion and latest updates.