aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Image will not change on the Browser...Saving on the Tomcat Problem.....HELP...Please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Image will not change on the Browser...Saving on the Tomcat Problem.....HELP...Please" Watch "Image will not change on the Browser...Saving on the Tomcat Problem.....HELP...Please" New topic
Author

Image will not change on the Browser...Saving on the Tomcat Problem.....HELP...Please

sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
Hi,
I worte a Servlet project using JBuilder 7 and TOmcat 4. THis is basically what i am doing...
I am getting an image from database and saving it to a folder in tomcat and then displaying it on a browser.
This application is used by multiple users...
I am saving the Image in Tom-cat...C:\JBuilder7\jakarta-tomcat-4.0.3\webapps\examples\Image1.jpeg
I am also displaying the image from that folder. The problem is when i run the application,
I am seeing the same Image on the screen..Its creating the different Image file, but the image is the same.
If i do a refresh on the page then it displays the new saved Image...
Also, If i save the image on my local and then display it from my local it changes the images as I
click on a Image list...
Following is how it works when i save it and display it from my local, but if i run my application from
another computer i am not able to see any of the images....Because its on my local.
fos = new FileOutputStream("C:/Image1.jpeg");
<img src="file:///C|/Image1.jpeg" height="855" name="myimage" align="middle" style="position:absolute;">;

And this is how i am doing when i am saving to the tomcat....I am able to display it on another computer
but would not change the image...
fos = new FileOutputStream("../webapps/examples/Image1.jpeg");
<img src="../Image1.jpeg" height="855" name="myimage" align="middle" style="position:absolute;">;

Can some one please tell me what could be the Problem....
Any help will be greatly appreciated....Thanks...
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
It is sound slike a browser caching problem.
Try to use something like inside a <HEAD>
<META HTTP-EQUIV="expires" content="Fri, 12 May 1996 14:35:02 EST">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">,
or you can try to add "?" + timestamp in milliseconds to image name
sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
Originally posted by Yuriy Fuksenko:
It is sound slike a browser caching problem.
Try to use something like inside a <HEAD>
<META HTTP-EQUIV="expires" content="Fri, 12 May 1996 14:35:02 EST">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">,
or you can try to add "?" + timestamp in milliseconds to image name

Thank you for your reply...
I tried this in my code but i am still getting the same image displayed on my browser....Unless i refresh it....
Do you think its the problem with the path where i am saving the Image....
How come it works when i save it on my local and then display it from my local it works fine...
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Meta tags won't help you in this case since it's the image that is caching, not some page where you would put the tags.
Are you using an absolute path to reference the image, or a servlet mapping?
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
Originally posted by Bear Bibeault:
Meta tags won't help you in this case since it's the image that is caching, not some page where you would put the tags.
Are you using an absolute path to reference the image, or a servlet mapping?
bear

Hi Bear,
Thanks for your reply...
I am not quite understood what you mean by absolute path to reference the Image, or a Servlet Mapping....
This is the path i an using when creating the Image and also displaying the Image...
fos = new FileOutputStream("../webapps/examples/Image1.jpeg");
<img src="../Image1.jpeg" height="855" name="myimage" align="middle" style="position:absolute;">;
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Instead of
<img src="../Image1.jpeg" height="855" name="myimage" align="middle" style="position:absolute;">
Try
<script>
document.writeln("<img src=\"../Image1.jpeg?" + (new Date()).getTime() + "\"" height=\"855\" name=\"myimage\" align=\"middle\" style=\"position:absolute;\">");
</script>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Ah, I see what Yuriy is proposing. By adding a random request parameter to the image URL, you may trick the browser into ignoring the cached version of the resource.
Without resorting to JavaScript to accomplish this in your JSP, you could achieve the same with something along the lines of:

or even

That said, even if this does solve your problem, I'd categorize it as a band-aid solution. On the other hand, since when and how a browser will check its cache is highly influenced by browser settings that you will have zero control over, this might be the best solutuion reagrdless of its supposed "elegance".
hth,
bear
[ March 27, 2003: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image will not change on the Browser...Saving on the Tomcat Problem.....HELP...Please