Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Mysql database image(blob) and put it on JSP page

 
sudheer yathagiri kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all experts,
i have one oppurtunity to get the blob image from mysql db and shown on jsp page with in <td>
for that i am writing ,
one BEAN class got getting and setting all the properties of a jsp page including image also.
when i come to jsp and putting content dynamically the remaining properties are perfectly appeared but not images ?? Why ?
I am creating a directory for each user inserting database image in my project/images folder .
For example, raju is a registered user and import some data along with image.
so,i create one folder for raju with in my project dynamically project/images/raju/img1
i am getting the img1 on server its con't create any folder and dont inssert any image.
please kindly help me out.

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you inserting the image onto the page? Are you creating valid HTML?
 
sudheer yathagiri kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:How are you inserting the image onto the page? Are you creating valid HTML?


yes, i have valid jsp page, With in that i want to insert the data ,
Let us take a sample example :
-----------------------------------
firstname :
lastname :
dob:
class :
rollno :
image(blob) :

These information can store in mysql.
once you just enter the roll number >> retrive all the data of the particular student along with the image on to my jsp page with in the <table><td>..
for that i am using java bean, but it con't get the blob image.
how can i solve this issue.



Thanks in advance .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Images in HTML are created via the image tag. The blob isn't useful on the JSP page. Please search this forum for previous discussions on writing a servlet to serve up the image data to the image tag.
 
sudheer yathagiri kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Actually,
once image is inserted in db,
create one folder in the locally,
<td><img src="path/<%=uname%>/<%=l.getImage()%>" alt="" width="65px" height="30px"></td>

This statement is not working ,

Is there any method.

Thanks for your valueble reply
 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going through the same sequence of wrong guesses that everybody else with this question does. Just save yourself some time and search the forum for "image servlet" or "download servlet".
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If l.getImage() is returning image data, that's wrong of course. The URL needs to be text, not image data. Listen to Paul and see the many times this has already been discussed.
 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BLOB type isn't quite the thing one would normally use to store large images.
Store the image in some path of your system.Then..
Just store this image path in your database (and not the actual image).
When you want to display an image on your webpage simply retrieve the path from your database and give this path in the <img> tag.

Example :an image is stored in following path: C:\Photos
then html code would be <img src="C:\Photos">
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manas Saxena wrote:then html code would be <img src="C:\Photos">

Not correct. The file protocol should never be used in web apps. That will attempt to look for the image file on the client's system. Not the server.
 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when the client uploads a picture then this picture should be stored in some server path and this server path is to be stored in database?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's one way. A blob in the database could be another.
 
sudheer yathagiri kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all replying for this question,

in which way i place the image in my jsp page.

Thanks to all,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already answered: an image tag in the JSP that references a servlet that serves up the image data.
 
sudheer yathagiri kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Bear,

Bear Bibeault wrote:Already answered: an image tag in the JSP that references a servlet that serves up the image data.


Can you send me the related link actually i am new to this technology , i can't understand what you say(above).

thanks for tour quick reply.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP is just a template for an HTML file. And in an HTML, images are specified with images tags.

The src of the image tag specifies a URL where the image is served from.

That URL can reference a servlet that reads the image from the database, sets the response headers accordingly, and sends the image data as the response.

The same conversation is going on here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic