aspose file tools*
The moose likes JDBC and the fly likes How i display image directly from Mysql database to jsp page inside div tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How i display image directly from Mysql database to jsp page inside div tag" Watch "How i display image directly from Mysql database to jsp page inside div tag" New topic
Author

How i display image directly from Mysql database to jsp page inside div tag

Vinod suryawanshi
Ranch Hand

Joined: Aug 08, 2012
Posts: 45
Hi friends,
I am storing jpg image in Mysql database and then retrieve it back from database table and displaying in jsp page. My table structure for that is very simple and as followed.

table column 'id' int(5) auto generate and primary key.
table column 'image' blob Notnull.

i use following code to display image in jsp page and its working fine.

This code is working properly, but my problem is, by using this code i can display only one image on one jsp page. I want to display image inside div tag. So i can keep multiple div tags on one page having different images and keep information about image in another div tag.
If anybody know any solution then please help me.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

JSP is merely a templating technology to create HTML to send to the browser. So given that the end result is HTML, then the answer to "How do I show an image in JSP?" is exactly the same as "How do I show an image in HTML?"

The answer, of course, is with an image tag.

So all that Java code in your JSP is useless -- and shouldn't be there anyway, see this JspFaq entry -- at least in the JSP. What you need is a servlet that sends the image data as a response that the image tag can use as its source.

See this article for an explanation of what JSP is and how it works.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vinod suryawanshi
Ranch Hand

Joined: Aug 08, 2012
Posts: 45
Thanks Bear Bibeault for your reply,
I did as you suggest and its working. i create one div tag as followed,

and its working fine, the way i want.
Thanks once again for your help....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Use a servlet not a JSP for the image. It may be working now, but it's extremely fragile. JSP is intended for text responses, not binary images.
 
 
subject: How i display image directly from Mysql database to jsp page inside div tag
 
Similar Threads
How to give Servlet response from Tag Handler class?
Display Image in JSP retrieved from database by servlet
display image after retrieving it from database?
displaying image from database
Displaying an image from byte[] into JSP