Java 1.7 applet CacheEntry preventing dynamic updates

爱⌒轻易说出口 提交于 2019-12-05 21:54:11

I've resolved this problem by using the following HTTP header in the server response:

Cache-Control: no-cache, no-store, no-transform

Now my Java 1.7 applet fetches the data from the server every time. Apparently Oracle changed how applets respond to these headers in Java 1.7. Previously (when we were using Java 1.6 applets), we had the following header:

Cache-Control: no-cache

and that worked in Java 1.6 but not in 1.7.

Had a similar problem with a Java applet and this fixed it:

Go to Control Panel (or System Preferences) > Java > General > Settings and then uncheck the box that says "Keep temporary files on my computer".

I'm having the same problem. I tried using URLConnection.setUsesCaches(false) but that does absolutely nothing.

I had to add the following to an http config file for apache. Then it worked.

<Directory /foo>
    <FilesMatch "\.(xml)$">
        Header set Cache-Control "no-cache, no-store, no-transform"
    </FilesMatch>
</Directory>

I already solved this problem that has been happening to me as well.

I add some fake arguments at the end of the URL such as date time or what ever that change every time i call the url.

for my own solution:

I genereate a date string

SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssz" );  
String today = formatter.format( new java.util.Date() );

and after that when i call the url i put the date sstring to the end of the url

new URL("http://url.to.something?fake_query_string=" + today);

with this solution, it'll fool java as a new url, so there's no any cache for this url, then java would always retrieve the data.

PS. it wouldn't be the best solution, but it saves me.

For me using setUseCaches(false) alone did not work. But calling both the following methods did work:

connection.setUseCaches(false);
connection.setDefaultUseCaches(false);

I suspect the reason is that my original url redirects to another url. The above code should work for all cases.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!