使用 WebContentInterceptor 为 spring mvc 3 的不同部分设置不缓存?
您好,我开发了一个动态 Web 应用程序,它使用 Ajax 从数据库获取数据并使 GUI 保持最新,但在使用 IE8 测试它时,我遇到了缓存问题。
我在 webmvc-config.xml 文件中使用以下代码来阻止浏览器缓存:
它的工作方式完全符合预期,但问题是现在浏览器显然不缓存任何内容。我想知道的是如何修改该 xml 代码,以便它适用于 Web 应用程序的 Ajax 部分(使用 5 个控制器文件进行控制);这样图标..等仍然被缓存?这些控制器文件的路径类似于“/admin/**”
我知道Spring WebContentInterceptor具有诸如“setCacheMappings”和“setPathMatcher”之类的属性,但是在网上我找不到这些属性的示例xml 配置文件。
任何帮助将不胜感激,这真的让我很头疼……谢谢。杰克
Hi there I have developed a dynamic web application that uses Ajax to fetch data from databases and keep the GUI up to date but while testing it with IE8 I am experiencing caching issues.
I used the following code in my webmvc-config.xml file to stop the browser from caching:
<mvc:annotation-driven />
<mvc:interceptors>
<bean id="webContentInterceptor"
class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0"/>
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
<property name="useCacheControlNoStore" value="true"/>
</bean>
</mvc:interceptors>
and it works exactly as it should, but the problem is that now the browser obviously doesn't cache anything. what I want to know is how to modify that xml code so that it applies to the Ajax parts of the web app (which are controlled using 5 Controller files); so that the icons..etc are still cached? The path to these controller files would be something like "/admin/**"
I know that the Spring WebContentInterceptor has properties such as "setCacheMappings" and "setPathMatcher" but there is nowhere online that I can find examples of these being using in the xml config file.
ANY help would be much appreciated, it's really doing my head in.. Thanks. Jake
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
中,您可以限制每个拦截器应应用的 URL 路径,如下所示:全部解释 此处。
In your
<mvc:interceptors>
you can restrict the URL path each interceptor should apply to, as follows:It's all explained here.