lelloman
lelloman

Reputation: 14173

Java applet and cache issue

I have an applet shown in a webpage with

<applet code="foo.class"></applet>

When i change the foo.class file in the server and access the page, it shows the older version. If I empty both browser and jvm caches, and then reload the page, it shows the current version. How can I tell the browser/jvm that this is another version of the same class?

And, if I access the html file locally, without any webserver, it shows always the current version even without cache refresh. What am I missing?

update:

when loading the applet with js, the generated html is:

<applet code="abcSynth.class" archive="miglayout-4.0-swing.jar" height="500" width="800"> <param name="cache_option" value="no"><param name="codebase_lookup" value="false">

Now, I found in java docs that codebase_lookup it's used when the main class is not provided with the .jar archive, just like this case. With false value, it throws ClassNotFoundException, with true value it starts (the old version). The code folder contains main class and other few .class files, the only .jar is the miglayout.jar, but since javadocs says "Typically applets are deployed with all the needed classes and resources stored in the applet JAR files." I wonder if I'm doing something wrong about .class/.jar depolying.

SOLVED Thanks it worked! Browser is still holding the older version in cache but after restart it shows the current version!

Final code I used is:

<object classid="java:myClass.class" 
          type="application/x-java-applet"
          archive="myJar.jar" 
          height="500" width="800" >
<param name="code" value="myClass.class" />
<param name="persistState" value="false" />
<param name="cache_option" value="no"/>
<param name="codebase_lookup" value="true"/></object>

Upvotes: 3

Views: 8296

Answers (1)

user592704
user592704

Reputation: 3704

Interesting question...

As a tip, you can use cache_option attribute so you can simply set not to cache you applet as...

<html>
<head>
<title>Test Applet</title>
</head>
<body>
Test applet...
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {code:'Test.class',
                      archive:'aTest.jar',
                      width:10, height:10};
    var parameters = {cache_option:'no'};
    var version = '1.6';
    deployJava.runApplet(attributes, parameters, version);
</script>
</body>
</html>

As an additional tip, try to use object tag instead of applet tag with the same parameters as:

<PARAM name="cache_option" value="no">

Report if it helped

Upvotes: 1

Related Questions