GeeCON Prague 2014*
The moose likes JSP and the fly likes Getting Mysql database image(blob) and put it on JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Getting Mysql database image(blob) and put it on JSP page" Watch "Getting Mysql database image(blob) and put it on JSP page" New topic
Author

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

sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
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

Joined: Jan 10, 2002
Posts: 61310
    
  66

How are you inserting the image onto the page? Are you creating valid HTML?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
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

Joined: Jan 10, 2002
Posts: 61310
    
  66

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

Joined: Mar 22, 2011
Posts: 35

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jan 10, 2002
Posts: 61310
    
  66

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

Joined: Mar 01, 2013
Posts: 38
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

Joined: Jan 10, 2002
Posts: 61310
    
  66

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

Joined: Mar 01, 2013
Posts: 38
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

Joined: Jan 10, 2002
Posts: 61310
    
  66

That's one way. A blob in the database could be another.
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
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

Joined: Jan 10, 2002
Posts: 61310
    
  66

Already answered: an image tag in the JSP that references a servlet that serves up the image data.
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35

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

Joined: Jan 10, 2002
Posts: 61310
    
  66

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.
 
GeeCON Prague 2014
 
subject: Getting Mysql database image(blob) and put it on JSP page