App Engine NO CACHE JSP [英] App Engine NO CACHE JSP

查看:125
本文介绍了App Engine NO CACHE JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有这个:

 <%
//设置过去时过期。
response.setHeader(Expires,Sat,1995年5月6日12:00:00 GMT);

//设置标准的HTTP / 1.1 no-cache标头。
response.setHeader(Cache-Control,no-store,no-cache,must-revalidate);

//设置IE扩展HTTP / 1.1无缓存头(使用addHeader)。
response.addHeader(Cache-Control,post-check = 0,pre-check = 0);

//设置标准的HTTP / 1.0无缓存头。
response.setHeader(Pragma,no-cache);
%>

但JSP仍在缓存中。我需要终止用户会话并重新登录才能重新加载JSP代码。



如何禁用应用引擎JSP缓存?

解决方案

它可能在那个时候来更改响应标头。他们会被忽略。您可以在其中 doFilter()方法如下所示:

  HttpServletResponse httpResponse =(HttpServletResponse)响应; 
httpResponse.setHeader(Cache-Control,no-cache,no-store,must-revalidate); // HTTP 1.1
httpResponse.setHeader(Pragma,no-cache); // HTTP 1.0
httpResponse.setDateHeader(Expires,0); //代理。
chain.doFilter(request,response);

web.xml中映射 url-pattern *。jsp ,它应该可以工作。



另见:




I want to disable the cache for a JSP file on my google app engine website.

I have this:

<%
        // Set to expire far in the past.
        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");

        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");

        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");

        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
%> 

But the JSP is still in cache. I need to kill the user session and login again in order to reload the JSP code.

How do I disable the cache for a app engine JSP?

解决方案

It might at that point be too late to change the response headers. They will simply be ignored. You can verify the presence of response headers in a HTTP debugger tool like Firebug.



In the JSP, you need to ensure that they are set before the response is committed (i.e. all headers are already sent; you cannot send another headers afterwards). I.e. ensure that they are in the very top of the JSP file and that no template text is before that piece of scriptlet. Template text may cause a commit of the response. The normal practice, however, is to use a Filter for this.

Implement javax.servlet.Filter wherein doFilter() method look like follows:

HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Cache-Control", "no-cache", "no-store", "must-revalidate"); // HTTP 1.1
httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0
httpResponse.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);

Map this in web.xml on an url-pattern of *.jsp and it ought to work.

See also:

这篇关于App Engine NO CACHE JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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