如何配置Spring以避免设置Pragma No-Cache [英] How to configure Spring to avoid setting Pragma No-Cache

查看:65
本文介绍了如何配置Spring以避免设置Pragma No-Cache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统基于Spring MVC,我检查了Spring是否自动设置了 PRAGMA:no-cache .用户可以通过SSL使用该系统.当用户尝试使用INTERNET EXPLORER 7或8下载某些内容时,会出现类似"Internet Explorer无法从服务器下载文件" 之类的错误(更多详细信息:

My system is Spring MVC based and I checked that Spring automatically sets PRAGMA: no-cache. The system is available to the users through SSL. When the users try to download something using the INTERNET EXPLORER 7 or 8 an error like "Internet Explorer cannot download file from server" appears (more details: http://support.microsoft.com/default.aspx?scid=KB;EN-US;q316431&).

我尝试将 WebContentInterceptor 配置为下面的代码,但是不起作用:

I tried to configure the WebContentInterceptor like the code bellow but does not work:

<mvc:interceptors>
    <bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
        <property name="cacheSeconds" value="2100" />
        <property name="useExpiresHeader" value="false" />
        <property name="useCacheControlHeader" value="false" />
        <property name="useCacheControlNoStore" value="false" />
    </bean>
</mvc:interceptors>

我该如何避免Spring发送Pragma:无缓存且与缓存控制有关?

What can I do avoid Spring send the Pragma: no-cache and related to Cache Control?

致谢!

推荐答案

您可以编写自己的自定义拦截器并将标头值设置为响应对象.拦截器不过是过滤器,因此可以覆盖过滤器并使用

You can write your own custom interceptor and set the header values to the response object. Interceptors are nothing but filters so override the filter and use the

prehandle和posthandle分别设置请求和响应头.

prehandle and posthandle to set the request and response headers respectively.

让我知道是否要这样做的特定示例.

Let me know if you want specific examples doing that.

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/**" />
        <beans:bean id="customInterceptor"
            class="org.example.interceptors.CustomInterceptor">
        </beans:bean>
    </mvc:interceptor>

</mvc:interceptors>




 public class CustomInterceptor implements HandlerInterceptor{

     public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView modelAndView) throws Exception {
     response.setHeader(...);}
}

这篇关于如何配置Spring以避免设置Pragma No-Cache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆