aspose file tools*
The moose likes Servlets and the fly likes Servlet can not show the proper photo from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet can not show the proper photo from database" Watch "Servlet can not show the proper photo from database" New topic
Author

Servlet can not show the proper photo from database

Shounak Kundu
Ranch Hand

Joined: Jul 29, 2010
Posts: 60

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....




Shounak
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
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

Joined: Jul 29, 2010
Posts: 60

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

Joined: Apr 15, 2008
Posts: 198
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

Joined: Jul 29, 2010
Posts: 60

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

Joined: Jul 27, 2005
Posts: 34
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
Bartender

Joined: Oct 14, 2005
Posts: 18906
    
    8

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.
 
 
subject: Servlet can not show the proper photo from database