Page caching discussion
2004-11-15 13:18
417 查看
Fixing problems with JSP and caching proxy server
Many of the proxy servers in use today are caching servers. These servers tend to recognize cgi, asp, and cfm as dynamic. They then always request a new page from the server rather than giving their client the page from the proxy cache. The problem is that most of these proxies do not recognize jsp as dynamic. To make matters worse, if the proxy server asks for the last modified date from the jsp page, it gets the compile date.
There is a simple fix for this. Add the following to your JSP pages where you have this problem.
%!
return current time to proxy
4000
server request
public long getLastModified(HttpServletRequest request) {
return System.currentTimeMillis();
}
%
To ensure that the web-browser itself will always obtain the latest version of the page, the following can be added to the beginning of your JSP (before any content has been committed).
response.setHeader( Cache-Control, no-cache );
response.setHeader( Pragma, no-cache );
response.setIntHeader( Expires, 0 );
------------------------------------------------------------------------------
Comment:
i have used this tags in my jsp page where i m using post method.
%response.setHeader( Cache-Control, no-cache ); response.setHeader( Pragma, no-cache ); response.setIntHeader(Expires, 0 ); %
Now the problem is whenever i submit my form and then go back & forward it gives me this warning.......so i m not able to view my page.....
Warning Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you. To resubmit your information and view this Web page, click the Refresh button.
------------------------------------------------------------------------------
You can stop pages caching their data... It's a pain (as there are buggy browsers out there), but this works for us:
<%
// 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");
%>
------------------------------------------------------------------------------
You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser.
You need both the statements to take care of some of the older browser versions.
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
If the above fails, try changing the first line to
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
The difference between no-cache and no-store is a bit dodgy, but apparently no-cache is the more polite keyword. However, please note that there are some problems with disabling page caching under IE 5.0 due to the unique buffering requirements of the browser. Please see the Microsoft knowledge base for details:
http://support.microsoft.com/support/kb/articles/Q222/0/64.ASP
http://support.microsoft.com/support/kb/articles/Q234/2/47.ASP
i added this code to the page.
<meta http-equiv="expires" content=<%= new java.util.Date() %>>
<meta http-equiv="no-cache">
added within the head tags.it worked for all browsers.
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1);
%>
I am also doing this at the very bottom of the JSP file:
</body> <!-- end of the content body -->
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
Many of the proxy servers in use today are caching servers. These servers tend to recognize cgi, asp, and cfm as dynamic. They then always request a new page from the server rather than giving their client the page from the proxy cache. The problem is that most of these proxies do not recognize jsp as dynamic. To make matters worse, if the proxy server asks for the last modified date from the jsp page, it gets the compile date.
There is a simple fix for this. Add the following to your JSP pages where you have this problem.
%!
return current time to proxy
4000
server request
public long getLastModified(HttpServletRequest request) {
return System.currentTimeMillis();
}
%
To ensure that the web-browser itself will always obtain the latest version of the page, the following can be added to the beginning of your JSP (before any content has been committed).
response.setHeader( Cache-Control, no-cache );
response.setHeader( Pragma, no-cache );
response.setIntHeader( Expires, 0 );
------------------------------------------------------------------------------
Comment:
i have used this tags in my jsp page where i m using post method.
%response.setHeader( Cache-Control, no-cache ); response.setHeader( Pragma, no-cache ); response.setIntHeader(Expires, 0 ); %
Now the problem is whenever i submit my form and then go back & forward it gives me this warning.......so i m not able to view my page.....
Warning Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you. To resubmit your information and view this Web page, click the Refresh button.
------------------------------------------------------------------------------
You can stop pages caching their data... It's a pain (as there are buggy browsers out there), but this works for us:
<%
// 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");
%>
------------------------------------------------------------------------------
You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser.
You need both the statements to take care of some of the older browser versions.
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
If the above fails, try changing the first line to
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
The difference between no-cache and no-store is a bit dodgy, but apparently no-cache is the more polite keyword. However, please note that there are some problems with disabling page caching under IE 5.0 due to the unique buffering requirements of the browser. Please see the Microsoft knowledge base for details:
http://support.microsoft.com/support/kb/articles/Q222/0/64.ASP
http://support.microsoft.com/support/kb/articles/Q234/2/47.ASP
i added this code to the page.
<meta http-equiv="expires" content=<%= new java.util.Date() %>>
<meta http-equiv="no-cache">
added within the head tags.it worked for all browsers.
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1);
%>
I am also doing this at the very bottom of the JSP file:
</body> <!-- end of the content body -->
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
相关文章推荐
- ISA Server 的故障排除工具(2)
- SQL Server 索引结构及其使用(一)--深入浅出理解索引结构第1/4页
- Microsoft Visual Studio .NET 2003制作安装程序
- Java面试题目
- 路由器网络接口解析
- 在做控件的存取控制时碰到的问题,请教各位!
- struts tag lib(1)
- sql server7.0数据库恢复
- ofbiz(open for business),银弹?人狼?
- 一个画图类,类似ms_chart的线图,适用于科学仿真数据分析(二)
- 越过调试这道槛——ASP.NET无法调试问题剖析
- Internet 怎么了?
- 使用 .NET 框架将现有代码作为 Web 服务提供
- 移植到 Windows 2000 和 COM+
- 用VB和MTS开发多层数据库应用系统
- 2004/09/17又重装系统了——知道vsconfig.xml是谁生成的吗?
- 用ASP备份数据库
- 玩转Xwindow 终端[转载]
- 企业运维—玩转 windows server 2016 DNS服务
- 企业运维—玩转 windows server 2016 DHCP服务