File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Displaying BLOB image in a jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying BLOB image in a jsp page " Watch "Displaying BLOB image in a jsp page " New topic
Author

Displaying BLOB image in a jsp page

meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
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, I wrote the following:



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

<img name= "titleImage"src="/Images?<bean:write name="images" property="imgData"/>" >

the servlet converts the byte to image and writes as an OutputStream



but I think when the byte[] gets passed from the jsp page to the servlet, it is sending it as null. can somebody tell me where i am doing wrong
[ September 23, 2005: Message edited by: meera rao ]
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Images are requested by the client in a separate HTTP GET. You'd have to create another Action that takes that separate request and returns the contents of the graphic along with the appropriate MIME type. Strut's "image" tag may be a starting point for you.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
can you please explain me in some more detail?
meera rao
Ranch Hand

Joined: Jun 30, 2005
Posts: 67
I have edited the first post, can anybody help me out
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Hi Meera

As Nathaniel previously said, all you need to do is to code a Struts Action that will take care of the picture 'retrieval', then call this action from the image tag of your JSP.

For exemple, you you might have a DisplayImageAction class with an execute method in it.
This action is supposed to return a stream of bytes, so you may set the returning type of the execute method to void instead of the default ActionForward since no forward is involved here.

Code the access of your stored procedure right into the execute method.
Basically, get a byte[] containing your picture, set the ContentType of your response (at least "image"), then send the bytes to your response outputStream (response.getOutputStream).

Once it's done, just call your Action from your JSP with basic HTML tag or Struts IMG tag. Don't forget to send a parameter in your request and use it in the Action to identify the file you need to retrieve :

<img src="displayImage.do?imageID=123" border="0">

Hope it helps...


Franck<p>--------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying BLOB image in a jsp page