Reputation: 164
I have run across the following problem: I have a web application which has a html page that uses ajax to request updates on a list from the servlet (the idea is that I want one user to be able to see the modifications that other users do on the list).
The problem was that the updates I did on the code of the servlet and on the .html file were not taken into consideration, even after restarting the server. I tried to fix this in various ways, from cleaning the project to creating another server, and after about two hours the solution I found was to delete temporary internet files and website files. However, I still need to do this every single time I do a modification in the code.
Then I discovered a new issue (actually a consequence of the first one). From my .html I use the javascript setInterval(...) method to do ajax requests on the servlet, but only the first request is proccesed and then, until I clean the temporary files again, it looks like it just keeps getting the initial response, even if the list was updated. I know that my code is not wrong because i did print screens on the servlet, and i can see that doGet(...) is only called once. If i delete temporary internet files during the execution of the program, doGet(...) is called again, the .html is properly updated and everything works fine.
So why is this happening and is there a way to fix it? I believe that eclipse/tomcat somehow caches information, but can this be disabled (I am using eclipse juno 4.2.1, apache-tomcat-7.0.47, and I am deploying the project directly from eclipse). Also, this issue didn't happen from the beggining, it used to work fine, I am not sure what I changed that caused it to stop working.
Upvotes: 3
Views: 2722
Reputation: 363
is there a way to fix it?
You just need the server to utilize the updated file rather than pulling from the cache. There are multiple ways to do this. For Tomcat 8.0.21, it seems true that saving a change in web.xml leads the server to use the files rather than the cache.
The quickest way I found to do this was to add a space, save, remove the space, save again. Also, I did it within a significant area such as within the url-pattern tags.
Upvotes: 1
Reputation: 40318
Servlet containers may send cache headers by default for static content OR the browsers themselfes will cache content that seems static (e.g. ending in .html
, .gif
and so on) and has no cache headers. That is why you needed to clean the browser cache. So a few solutions (there may be others):
Add cache-breaking request parameters for GET requests, e.g. instead of asking for
http://host/app/index.html
ask for:
http://host/app/index.html?q=12345678
where 12345678 is a random numbe or, the current timestamp (jQuery does it this way if you specify cache: false
)
Upvotes: 1