Tomcat can't see newly created static files and is server-side caching the old files

£可爱£侵袭症+ 提交于 2019-12-18 06:57:26

问题


I use Tomcat 7 on Windows XP.

  • I have a directory with static files (HTML, CSS, JS) in %TOMCATDIR%/webapps/myapplication.
  • They're accessible via localhost:8080/myapplication

When a change happens to a file in my server dir, it is not reflected:

  • modified files are returned (200 OK) the same as previously (tested with Fiddler; for sure not a browser cache issue - cleared cache, using different browsers etc.),
  • newly created files in that directory are not accessible (404).

The above happens no matter how many times I try to reload the file, or even add query string to it (img.jpg?timestamp=...).

In %TOMCATDIR%/conf/context.xml I've set various directives to disable server-side caching:

<?xml version='1.0' encoding='utf-8'?>
<Context antiResourceLocking="true" cachingAllowed="false" cacheMaxSize="1" cacheTTL="1">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

What is wrong?


回答1:


The solution seems to be remove antiResourceLocking="true".

If anyone's more knowledgable about the topic, or know how to workaround it other way, I'll be grateful.




回答2:


Tomcat 8 - disable caching of static resources:

context.xml

     <Resources cachingAllowed="false"/>



回答3:


Finally the solution is to replace %TOMCATDIR%/conf/context.xml file content within :

<?xml version='1.0' encoding='utf-8'?>
<Context cachingAllowed="false" cacheMaxSize="1" cacheTTL="1">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>


来源:https://stackoverflow.com/questions/11333462/tomcat-cant-see-newly-created-static-files-and-is-server-side-caching-the-old-f

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