2013-09-24 135 views
0

我有一个JSP返回此HTML 5:缓存与JSP和HTML5:如何禁用缓存服务器端

<html> 
    <head> 
     <title>Application</title> 
     <!-- Some script includes here --> 
    </head> 
    <body> 
     <!-- My html here --> 
    </body> 
</html> 

目前用户需要禁用缓存到浏览器,否则老页面每次都会重新加载。

我试图强迫没有缓存在这样一个小脚本,但没有成功:

<% 
response.addHeader("Cache-Control","no-cache"); 
response.addHeader("Expires","-1"); 
response.addHeader("Pragma","no-cache"); 
%> 

ASDE的事实,小脚本将不会是一个很好的解决方案,有没有在JSP工作任何方式禁用缓存?

回答

0
Cache-Control 

上述头必须是一个跨浏览器one.Might是造成问题

如果您在使用Apache Tomcat的context.xml变化

<Context cachingAllowed="false"> 

尝试

response.addheader('Cache-Control: no-cache, no-store, must-revalidate'); 
0

你可以阅读文档http://tomcat.apache.org/tomcat-6.0-doc/config/context.html 其中说

cachingAllowed

如果这个标志的值为true,将用于静态资源缓存。如果未指定,则标志的默认值为true。

+0

有JBoss中类似的东西? – user1883212

+0

@ user1883212我对jboss并没有太多的工作,但希望您找到https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Administration_And_Configuration_Guide/jbosscache.chapt.html链接有用。 – AurA

0

鉴于您正在使用jsp文件,您正在Web容器中运行此文件。我们通过使用javax.servlet.Filter来设置标题值。

我不知道任何开放源代码过滤器已经做到了这一点,但是写出自己并不难。

我们的HTTP设置的页眉/ 1.0:

httpResponse.setDateHeader("Expires", 0L); 
httpResponse.setHeader("Pragma", "no-cache"); 

我们的HTTP设置的页眉/ 1.1:

httpResponse.setHeader("Cache-Control", "private,no-store,no-cache");