Is there a way to delete older version of an applet from browser's cache? The things I have already tried to prevent the cache problem in first place are:
1- To set "no-cache" in HTTP response header, I placed following script on the top of my jsp:
<%
if (request.getProtocol().compareTo("HTTP/1.0") == 0) {
response.setHeader("Pragma", "no-cache");
} else if (request.getProtocol().compareTo("HTTP/1.1") == 0) {
response.setHeader("Cache-Control", "no-cache");
}
response.setDateHeader("Expires", 0);
%>
2- While deploying applet 'cache_option' is set to 'no'
But of no use. I was now wondering if there is a way to programatically delete this applet jar file from cache?
[UPDATE]
Providing a unique url for applet each time doesn't look like a good idea in my case. As, in my case applet reloads(refresh) itself after a time (say at mid-night, using Timer), hitting on a url
applet.getAppletContext().showDocument(url);
It would be difficult to communicate new url to applet
The answer you got on your other question also applies here: Provide a unique url for your applet each time. It's not humor, as lots of people are using this technique and it would solve your problem.
these links might be of your help:
Applet Caching and Installation in Java Plug-in
how-to-clear-cache-to-reload-applet
How to disable http caching in applet
How to disable browser applet cache..?
Java applet cached forever, not downloading new version?
There are a couple of solutions to your problem. The one which is discussed more in the links, is to use a different name for every applet jar file. Append version number or anything so as to ensure that browser loads the applet from the server every time it runs, rather then from the cache. You can get more help from the above pasted links. Thanks.
P.S. The links are pasted in order of relevance.
Related
I want to download a source of a webpage to a file (*.htm) (i.e. entire content with all html markups at all) from this URL:
http://isap.sejm.gov.pl/DetailsServlet?id=WDU20061831353
which works perfectly fine with FileUtils.copyURLtoFile method.
However, the said URL has also some links, for instance one which I'm very interested in:
http://isap.sejm.gov.pl/RelatedServlet?id=WDU20061831353&type=9&isNew=true
This link works perfectly fine If open it with a regular browser, but when I try to download it in Java by means of FileUtils -- I got only a no-content page with single message "trwa ladowanie danych" (which means: "loading data...") but then nothing happens, the target page is not loaded.
Could anyone help me with this? From the URL I can see that the page uses Servlets -- is there a special way to download pages created with servlets?
Regards --
This isn't a servlet issue - that just happens to be the technology used to implement the server, but generally clients don't need to care about that. I strongly suspect it's just that the server is responding with different data depending on the request headers (e.g. User-Agent). I see a very different response when I fetch it with curl compared to when I load it in Chrome, for example.
I suggest you experiment with curl, making a request which looks as close as possible to a request from a browser, and then fiddling until you can find out exactly which headers are involved. You might want to use Wireshark or Fiddler to make it easy to see the exact requests/responses involved.
Of course, even if you can fetch the original HTML correctly, there's still all the Javascript - it would be entirely feasible for the HTML to contain none of the data, but for it to include Javascript which does the actual data fetching. I don't believe that's the case for this particular page, but you may well find it happens for
try using selenium webdriver to the main page
HtmlUnitDriver driver = new HtmlUnitDriver(true);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl);
and then navigate to the link
driver.findElement(By.name("name of link")).click();
UPDATE: I checked the following: if I turn off the cookies in Firefox and then try to load my page:
http://isap.sejm.gov.pl/RelatedServlet?id=WDU20061831353&type=9&isNew=true
then I yield the incorrect result just like in my java app (i.e. page with "loading data" message instead of the proper content).
Now, how can I manage the cookies in java to download this page properly then?
I am using JSONP to answer AJAX calls on a different server than the site is on. It works pretty well, except that on IE, I can't maintain a session.
The site answering the request uses Java Servlets. It works in Firefox, but I in IE I have problems because it doesn't accept the cookies. (I can make it work by changing the security settings.)
From there I tried putting the sessionid in the url of the request:
listAction: server+'/site/gateway.jsp?current=page&next=something&jsessionid='+session+'&callback=?'
(I write callback=? because I am using jQuery and that is how you can do Jsonp.)
It still doesn't work. Did I write the session wrong? Is it still looking at my cookies? Can I possibly configure my servlet to load the session that I want it to load?
This is actually the same problem that you get with iFrames. You need to set a p3p header.
request.setheader('P3P: CP="NOI ADM DEV COM NAV OUR STP"');
Why does IE block you from using cookies with JSONP, but allow you if you just add some header? Who knows. The header represents a privacy policy. And I guess they don't think malicious hackers will be dishonest about their privacy policy.
If you sell information about your users or have other reasons to worry about a lawsuit from your users, you should make sure your p3p header accurately reflects your privacy policy, so you'll have to do a bit more research.
This is the same question but about the iFrames: Cookie blocked/not saved in IFRAME in Internet Explorer
My applet currently accesses a url and prints the contents at that url. The problem is that url is fixed, but that url renders something different depending on the website's state. My applet will print a cached version of the contents at the url instead of actually retrieving the new one. I don't want the user to have to restart their browser just to get this applet to work properly and the separate_jvm tag only helps if the user refreshes the page. If I manually go into the java console and clear the classloader cache that seems to make it work.
Pretty much I want to be able to programmatically clear a JVM's cache.
After careful searching I haven not been able to find a solution, but, I was able to remember of the classic timestamp solution. If I append the timestamp to the url, even if it's not used, it will never have a cache problem.
What you need to do is set the HTTP 1.1 Cache-Control request header to no-cache. How you do that depends on the library you are using. If you are using the Apache HTTP Client, take a look at HttpRequest.setHeader(). Changing the timestamp works, but tends to clog caches with stuff that can't be reused.
I have a Java/Wicket page that generates a JNLP file that launches my company's software. This class will optionally take some url parameters and embed them as arguments in the JNLP. When the user launches this JNLP file the client application will perform some function based on those parameters. If the client software is already running on the machine, hitting the JNLP page will instead try to feed these parameters via a remote call to the running client instead of launching a new page.
This part is where I'm having issues. On IE, Firefox and Chrome I could open a new client, but trying to hit the same URL again would instead return a JNLP file. I found that clearing the browser cache fixes this issue on all browsers. Also, I cannot seem to hit breakpoints in the JNLP class, which enforces my hunch that this is more of an issue with the request than something strange with Wicket.
I put the following code in my page class, which extends org.apache.wicket.markup.html.WebPage:
#Override
protected void setHeaders(WebResponse response) {
getPageMap().remove(this);
HttpServletResponse httpServletResponse = response.getHttpServletResponse();
if (httpServletResponse != null) {
httpServletResponse.setDateHeader("Expires", 0);
httpServletResponse.addHeader("Cache-Control", "no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0");
httpServletResponse.addHeader("Keep-Alive", "timeout=3, max=993");
}
}
This doesn't seem to work, as Firefox 3.6 still seems to cache the result. IE 7 will work but only after trying the link I create a few times. I don't know a lot about web development and Wicket and this is new to me so it's possible I'm missing something simple.
TL;DR: How do I get a Wicket page to not cache on the client browser?
A hack used in some of the Wicket internals (see for example the source for org.apache.wicket.markup.html.image.NonCachingImage) is to add random noise to the url.
Basically, if you're generating the urls that the browser calls, you can add a parameter ignored by the web application that varies randomly and fools the browser into ignoring its cache.
Please check the following page:
https://web.archive.org/web/20120104201334/http://palisade.plynt.com:80/issues/2008Jul/cache-control-attributes/
Firefox should honor the "Cache-Control" header.
I don't know Wicket very well but have you tried using WebResponse.setLastModifiedTime(Time time)? I know FF sends an If-Modified-Since header to which your server would reply with 304 Not Modified or the normal response.
It would seem natural to me that your server would check the lastModifiedTime on WebResponse to decide.
If that doesn't help I would suggest you get Firebug for Firefox and take a look at the requests and responses.
response.setHeader( "Expires", "0" );
response.setHeader( "Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, private" );
response.setHeader( "Pragma", "no-cache" );
This works with IE, Firefox and so on, the only browser with which it certainly does not work is konqueror.
Wicket 6.11.0:
Application.get().getResourceSettings().setDefaultCacheDuration(Duration.NONE);
Have you ever tried to load pages using window.location.replace?
I have a Java web application running in JBOSS with Tomcat with two web applications (contexts) running on it.
A button press on one of the applications opens runs a javascript command to open a new window with a page from the other.
The problem I seem to be having is that this raises a security alert in IE. with the following message:
I can't really ask my customer to add an exception to "http://" what are the likely causes for it not picking up the site?
The browser is correctly pointed at the full url for the page (Ie www.something.net:8080/blah/somepage.jsp) the browser is IE7 with enhanced security running on windows 2003.
You need to uninstall "Explorer Enhanced Security", which is on by default in Windows Servers, before IE will act like a normal browser. :)
Workstations shouldn't get this problem.
IE Enhanced Security Configuration is deliberately designed to prevent general purpose browsing from servers. Folks who want to do workstation-style browsing and just happen to be on a server SKU should disable ESC.
What's the exactly line of code? window.open("http://fullURL", etc), or something like var v=window.open("about:blank"); v.location.href=etc ?
Do the two applications have different domains? IE is preventing the cross-site scripting.
Can you not just have a link to the other site?
EDIT: If this is on Windows Server 2003, then the only way that I've managed to get around it is to disable to enhanced browser security. If this is the case, then you shouldn't really be browsing from a server in the first place.
Edit2:I'm guessing that it is the enhanced browser security that is doing this.
Check out this link: http://support.microsoft.com/kb/815141 on info about it.
Your choices are to either to disable it, add an exception for that site, or use another browser.