aspose file tools*
The moose likes JSP and the fly likes Displaying image problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying image problem" Watch "Displaying image problem" New topic
Author

Displaying image problem

mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Hi ranchers,

I am developing an web application with servlets and jsp. I have an issue to store images. I am storing images in folder and their relative path's in mysql database.


when I retrieve path from database then using <IMG> tag i have displayed image like:

<img src="<%=pathvariable%>" alt='' height=400 weight=100>

It is working fine with internet explorer but not working (that is Not displaying image) in chrome/mozilla.

How to display that image in all browsers....

please reply me as soon as possible.


Thanks in advance...
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

Actually, this has nothing to do with servlet or jsp...
but pure HTML...and very strange that it works in only in IE...


what is the final html code of your image tag?

Check the path where you are (the url), the path in your src attribute, and check if it is actually right what you are doing...
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

olivier dutranoit wrote:Actually, this has nothing to do with servlet or jsp...
but pure HTML...and very strange that it works in only in IE...


what is the final html code of your image tag?

Check the path where you are (the url), the path in your src attribute, and check if it is actually right what you are doing...



Thanks for reply,

when i viewed the source of generated html (src) it is displaying correct path.

that is if my image in C:\netbeansprojects/build/web/image1.jpeg the path displaying correct as it is when i copy that address and pasted in my computer it is displaying image .

It is working fine in Internet Explorer but not in other browsers...

Thanks in advance..
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

there is your problem:

C:\netbeansprojects/build/web/image1.jpeg

if you work locally, you can use images from your disk

but watch the "/" and "\"

if locally, you should use :

C:\netbeansprojects\build\web\image1.jpeg

if you deploy your project on a real server...this will never work
than you will have to give an network path...

like (for example absolute path)

htttp://www.mysite.com/images/myimage.jpg


why is it working in IE? everything works in because IE. that browser doesn't care about standards etc etc...

if something works in FF or chrome or etc... then it will certainly work in IE...
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

ok I have changed the path to

"C:\NetbeanProjects\Image\build\web\image1.jpg" this is correct path. Still the problem comes It is not working in chrome/mozilla browsers...
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

My Servlet code is:

olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

thats very weird...
i see in your servlet that you do

response.setContentType("image/jpeg");

while writing your html code...

why you do that? there is no need...

you only need to do this if you actually send an image on byte level...but this is not the case in here...

maybe this could be the problem?
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

olivier dutranoit wrote:
you only need to do this if you actually send an image on byte level...but this is not the case in here...

maybe this could be the problem?


Thanks for reply,

I have removed that element response.setContentType(); Still the problem is there how to avoid that reply me....

Thanks in advance..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Using a file path will not work anywhere else but on your computer. Is that what you want?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Bear Bibeault wrote:Using a file path will not work anywhere else but on your computer. Is that what you want?


Sir I am storing image path in mysql database table with an id. To display that image using my jsp it is not working sir(that is working in internet explorer but not in other browsers) what I have to do..

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Then I'm really confused. If the image is in the DB, then why does your code use a file path to show it?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

My guess: the "image path" is the file path on the server. This of course is useless on any computer except the server; but if your browser is running on the same machine as the server, a link using the file path might actually work in some browsers.
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Bear Bibeault wrote:Then I'm really confused. If the image is in the DB, then why does your code use a file path to show it?


Sir,

Actually I am storing images in my local drive (that is creating new directory as new File("/root/example").mkdir(); ) and storing images to this newly created folder and storing relative path in data base. So when i want to show images to users by getting their id's I have to fetch path from my database and show related images to user.
mike mimmis
Ranch Hand

Joined: Feb 11, 2011
Posts: 57

Paul Clapham wrote:My guess: the "image path" is the file path on the server. This of course is useless on any computer except the server; but if your browser is running on the same machine as the server, a link using the file path might actually work in some browsers.


Thanks for reply,

Your guess is absolutely correct. In my local system only i was checking if images are displaying correct or not . but it is working only in Internet Explorer but not in other browsers what is the reason for this? and how we avoid that.

Actually I have to upload 18000 images into my sql database if I store all images to Mysql database as Blob type the performance is reduced and It will slow down if we upload other images if required.To avoid this problem I am storing all images into folder and their path's into mysql database table. If there is any alternative way to deal with this problem please reply me as soon as possible...

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

I still don't really see what the problem is. If the images are part of the web app, then just use the proper HTTP URL (not a file URL) to address them. Otherwise, you'll need to write a servlet to stream them as a response. There are many examples you can search for that do just that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying image problem