• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vinod suryawanshi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic