File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Refresh problem in applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Refresh problem in applet" Watch "Refresh problem in applet" New topic
Author

Refresh problem in applet

Yogesh Dhond
Greenhorn

Joined: Jul 19, 2006
Posts: 17
Hi,
I have a problem with my applet. My applet load the image in the applet using double buffering with name image.jpg (first page). This image is sotre on the server and picked by my applet. Then i give the user, facility to crop the image and add color to the image if he finds it neccessary. This is done by calling different applet. After this, user has to save the image, which is again saved with the same name on the server, i.e. image.jpg.
But when i again try to open the image loading page( first page), it displays me the old image only within the applet and not the new modified image. I guess, this is happening because browser has cached my previous first page applet. I can only see the modified image when i click on the refresh bustton on the browser.
Is there any solution for this, so that user shouldnt be doing refresh each time he modified the image?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
I don't think it's the browser caching the image, because the Sun JVM uses its own networking code (which may have a chache, too, I'm not sure). Is the server actually accessed the second time? Maybe it is, but responds with a 304, signalling that it thinks the file hasn't changed.


Ping & DNS - updated with new look and Ping home screen widget
Yogesh Dhond
Greenhorn

Joined: Jul 19, 2006
Posts: 17
Ok !! something I am getting in this>>.
I have one more problem ... can i call another applet from first applet
and pass some of the variables of first applet to this called applet.
And does it mean that i m loading next applet within the same first applet?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
What do you mean by one applet calling another applet? Are those on the same web page or on different pages?

There are ways of getting applets to communicate with one another, but it's more complicated than a method call from one object to another.
Yogesh Dhond
Greenhorn

Joined: Jul 19, 2006
Posts: 17
currently my applet is communicating with PHP/html . So i get data from
php file which passes me param names containing photoimage.jpg with its path.
After this, my applet is loaded which takes those param names and picks the
photoimage from stored location mentined in the path. This applet has save button inorder to save the image. Also there are html buttons like "Proceed" and "Edit Image".
If user wants to edit image for enhancements, he clicks on the "Edit Image" link which loads another applet in the same browser window which helps the user to perform photoimage enhancement task like changing color and giving effects. Here also within an applet theres is save button which saves the enhanced image. The new enhanced image is also saved as photoimage.jpg in the same location replacing old file.
So when user comes back to the first page, using html link, the first applet is loaded. But the image shown here is still the old unmodified photoimage.jpg and not the new. If i check the image which is saved on the server in the path, the new modified image is shown.
If i close the browser and then start the operation all over again, then this time the new image is loaded, which is quiet obvious.
Somehow i want the browser to load the new image wthout refreshing or closing it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Which mechanism does the applet use to access the image? HttpUrlConnection?

It goes back to what I said in my first post: either the JVM may be caching the image, or the web server may be signalling that it's unchanged. You should determine which of these it is.
Yogesh Dhond
Greenhorn

Joined: Jul 19, 2006
Posts: 17
I am using following
java.net.URL imgURL =test.class.getResource(path);
if (imgURL != null)
{
return new ImageIcon(imgURL);
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Using getResource will indeed cause the image to be cached (kind of), because the classloader will load resources only once, and then never again.

You need to switch to using HTTP more directly to retrieve the image. The Applet FAQ talks about that.
Yogesh Dhond
Greenhorn

Joined: Jul 19, 2006
Posts: 17
Thanks for your suggestion...
currently we are now saving the image with different name so that, theres
no caching problem. Also using http instead of direct file resource.
I am not finding the proper topic to search in the link, you have provided.
 
Consider Paul's rocket mass heater.
 
subject: Refresh problem in applet
 
Similar Threads
Revisiting an Applet - Urgent
applet in browser
uploaded image with same name does not reflect on page immediately
Applet revesit problem - Help pls
How to set 'If-Modified-Since ' header