3
votes

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>
1
1) "I have an applet shown in a webpage with <applet code="foo.class"></applet>" I am surprised you see anything given that applet specifies no width or height. Validate the HTML. 2) The browser/JRE caches applet classes. Flush the cache by typing c(?) in the Java Console. Then reload the page. 3) As more general advice, test applets as far as possible in the IDE and applet viewer. Prefer a JWS launched app. to an applet.Andrew Thompson
1) Of course there are width height and archive attributes, but they have nothing to do with the question 2) I know how to clear the cache, but I can't expect final users to do it, and that's why (3)) I'm talking about browser and not applet viewerlelloman
@user1527232 I edited my answer. Watch it please...user592704

1 Answers

1
votes

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