Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet can not show the proper photo from database

 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have successfully uploaded the images to my database.
But , when I am trying to show the images , it is always showing the first image ( image from the first row ).

This is my values from the database table :



But, when I am trying to retrieve the image of UPLOADID=1002, I am still getting the image with UPLOADID=1000.

Here's my code in servlet :



Please help....



 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely this is because the web browser you use caches the image locally and if the servlet you use uses the exact url you used to create the first image then the cached image is shown instead.

You can verify if this is the case for example by adding some random parameter at the end of the servlet url. So for example if this is you normal url
http://localhost:8080/webapp/ServletName
try this
http://localhost:8080/webapp/ServletName?random=8585

If this solves it then you can start searching a way to either prevent the browser caching the image or by adding some randomly changing parameter in the end of the url programmatically.
 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, you are right .

I tried this URL : http://localhost:8080/new_test/PhotoShow?rand=100

Still it's showing the same photo.

I am using Google Chrome.

How can I overcome this problem, advise me please.....
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How am I right?
If adding some random parameter at the end of the url did not change the image then I probably was wrong and the problem is somewhere else.

Sorry I could not help you. Maybe someone else has a better idea.

EDIT: Maybe describing your code/environment more could help solving your problem. For some reason you do the query to database twice in you code. Why? In your code you have put a static uploadid in your query but how are you going to change it in the real version (to fetch different images)? etc etc
 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I misinterpreted your statement previously. Actually , I am now testing the database table, that's why I gave the static uploadid. In actual code, I would replace it with dynamic uploadid.

So, is there any way out ? Please help me.....
 
Nauman Hasan
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what the problem could be but just to eliminate browser caching could you switch the image in row 1 with the one from row 2. That way you will know if the issue on the browser end or the DB end.

~Nauman
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shounak Kundu wrote:Actually , I am now testing the database table, that's why I gave the static uploadid. In actual code, I would replace it with dynamic uploadid.

Don't spend a lot of time trying to test code which isn't going to be the actual code. And spend more time testing code which is going to be the actual code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic