*
The moose likes JSP and the fly likes how to display image in JSP from oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to display image in JSP from oracle" Watch "how to display image in JSP from oracle" New topic
Author

how to display image in JSP from oracle

Chintan Shah
Greenhorn

Joined: Jun 29, 2005
Posts: 27
Hi,
i have stored..the path of images in oracle..and i need to retrieve image in JSP through that path stored in oracle.
how do i do it?
please let me know. its urgent.
chintan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Originally posted by Chintan Shah:

please let me know. its urgent.


Please read this in order to understand why putting this phrase in your post may actually prevent people from answering.
[ March 21, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chintan Shah
Greenhorn

Joined: Jun 29, 2005
Posts: 27
alright i understood..sorry about that..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

No prob, just trying to help you make the most of Javaranch as a resource.
Jason Kwok
Ranch Hand

Joined: Mar 31, 2005
Posts: 126
The way I would do this, is to run my query to get the image paths, and if they are related to something bigger like a book or product of some sort, I would store them into a bean along with the rest of the individual product's information.

I would then send the beans back, typically inside an ArrayList, in the response to the JSP page. The JSP page would then have to unpack the beans from the ArrayList and then using the appropriate JSP code to display the image.

For example: <IMG SRC="<%=myProductBean.getImagePath()%>">
where myProductBean is one of the beans, and getImagePath() is a method defined in the bean class.

Hope that helps!
[ March 21, 2006: Message edited by: Jason Kwok ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Passing the image data to the JSP will serve no purpose (and in an ArrayList? I don't see how that would work).

The image data would never be sent to the JSP which has no means of dealing with it. Rather, the JSP should render an img tag along the lines of



Then, an image serving servlet would fetch the image data from the DB (preferably delegating the task to a class or bean that's smart about caching the data) and send the image data as the response after setting the appriopriate MIME headers.
[ March 21, 2006: Message edited by: Bear Bibeault ]
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
Bear,

I think he is storing the path (as varchar) and the not actual image (not LOBs) to the Oracle.
So I think retrieving it was correct.
But the care has to be taken for converting the physical to the context path.

Originally posted by Bear Bibeault:
Passing the image data to the JSP will serve no purpose (and in an ArrayList? I don't see how that would work).

The image data would never be sent to the JSP which has no means of dealing with it. Rather, the JSP should render an img tag along the lines of



Then, an image serving servlet would fetch the image data from the DB (preferably delegating the task to a class or bean that's smart about caching the data) and send the image data as the response after setting the appriopriate MIME headers.

[ March 21, 2006: Message edited by: Bear Bibeault ]


Manesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Originally posted by Dilip Kumar Jain:
I think he is storing the path (as varchar) and the not actual image (not LOBs) to the Oracle.


Ah, yes, upon re-reading I think you are correct.

In that case, it depends what the OP means by "path"? Is it the URL of the image, or the file system path? In the latter case, either the path must be converted to the corresponding URL (assuming that the file path is mapped as appropriate for web server access), or we're back to a servlet to read the file and serve the data.
Satish SN
Ranch Hand

Joined: Apr 19, 2005
Posts: 70
Hi Chintan,

Typically this kind of problems are solved by keeping the imgPath as context level variable and corresponding image name is picked up from the oracle DB in your case and simple pass the

u store the images in certain folder on the server where the application is runing

put the path in the ServletContext and retrieve the same in the jsp and build ur imagepath accordingly by appending the image name retrived from the DB and pass the imagepath.

<img src="<%=imagePath%>">


Satish SN<br />SCJP 1.4 & SCWCD 1.4
Chintan Shah
Greenhorn

Joined: Jun 29, 2005
Posts: 27
Hey, thanks to everybody, for your guidance
ya, i stored the actual image path in oracle db..as varchar
then i passed query, retrieved path in String variable in JSP and then displayed it through imgsrc in JSP.
Well, thanks once again for all of your help
i am indeed thankful to every one of you.
Sorry..once again..about urgent thing.
chintan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to display image in JSP from oracle