我想在我的google应用引擎网站上禁用JSP文件的缓存。
我有这个:
<%
// 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");
%> 但是JSP仍然在缓存中。为了重新加载JSP代码,我需要关闭用户会话并再次登录。
如何禁用应用程序引擎JSP的缓存?
发布于 2011-01-21 18:56:30
此时更改响应头可能为时已晚。他们将被忽视。您可以在HTTP调试器工具(如火虫 )中验证响应头的存在。

在JSP中,您需要确保在提交响应之前设置它们(即,所有标头都已经发送;之后不能再发送其他标头)。也就是说,确保它们位于JSP文件的最顶端,并且在该脚本块之前没有模板文本。模板文本可能导致响应的提交。然而,通常的做法是为此使用Filter。
实现javax.servlet.Filter,其中doFilter()方法如下所示:
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);在web.xml中将其映射到url-pattern of *.jsp上,它应该能工作。
另请参阅:
https://stackoverflow.com/questions/2705008
复制相似问题