JSP 開(kāi)發(fā)之Servlet解決網(wǎng)頁(yè)緩存問(wèn)題
JSP 開(kāi)發(fā)之Servlet解決網(wǎng)頁(yè)緩存問(wèn)題
(1)我們?yōu)槭裁匆乐褂斡[器頁(yè)面緩存的問(wèn)題:
所以在不需要緩存的頁(yè)面中需要實(shí)現(xiàn)不緩存頁(yè)面;
代碼如下:
package com.lc.HttpTest; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class CacheJiejue extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); //指定該頁(yè)面不緩存 response.setDateHeader("Expires",-1); //IE游覽器支持的 //保證兼容性 response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragme", "no-cache"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
(2)但是如果要實(shí)現(xiàn)特定時(shí)間內(nèi)的頁(yè)面緩存 則代碼如下:
package com.lc.HttpTest; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class CacheJiejue extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); //指定該頁(yè)面不緩存 //response.setDateHeader("Expires",-1); //IE游覽器支持的 //緩存一定的時(shí)間 緩存 一天的時(shí)間 response.setDateHeader("Expires",System.currentTimeMillis()+3600*1000*24); //保證兼容性 response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragme", "no-cache"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
以上就是Servlet解決網(wǎng)頁(yè)緩存的實(shí)例詳解,如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Java,JSP,Servlet獲取當(dāng)前工程路徑(絕對(duì)路徑)問(wèn)題解析
- JSP 開(kāi)發(fā)之THE SERVLET NAME ALREADY EXISTS.解決方法
- JSP中通過(guò)Servlet 將服務(wù)器硬盤(pán)圖片并展示到瀏覽器
- Jsp+Servlet實(shí)現(xiàn)購(gòu)物車(chē)功能
- 淺談Servlet轉(zhuǎn)發(fā)到JSP頁(yè)面的路徑問(wèn)題(必看)
- JSP 開(kāi)發(fā)之servlet中調(diào)用注入spring管理的dao
- JSP開(kāi)發(fā)Servlet重寫(xiě)init()方法實(shí)例詳解
- JSP 中Servlet的自己實(shí)現(xiàn)
相關(guān)文章
JSP輸出HTML時(shí)產(chǎn)生的大量空格和換行的去除方法
在WEB應(yīng)用中,如果使用jsp作為view層的顯示模板,都會(huì)被空格/空換行問(wèn)題所困擾.2009-10-10加快JDBC設(shè)計(jì)中JSP訪問(wèn)數(shù)據(jù)庫(kù)
加快JDBC設(shè)計(jì)中JSP訪問(wèn)數(shù)據(jù)庫(kù)...2006-10-10struts2+jquery實(shí)現(xiàn)ajax登陸實(shí)例詳解
這篇文章主要介紹了struts2+jquery實(shí)現(xiàn)ajax登陸,需要的朋友可以參考下2014-07-07簡(jiǎn)單實(shí)現(xiàn)jsp分頁(yè)
這篇文章主要為大家詳細(xì)介紹了如何簡(jiǎn)單實(shí)現(xiàn)jsp分頁(yè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12JSP Spring 自動(dòng)化裝配Bean實(shí)例詳解
這篇文章主要介紹了JSP Spring 自動(dòng)化裝配Bean實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04JSP教程(六)-怎么在JSP中跳轉(zhuǎn)到別一頁(yè)面
JSP教程(六)-怎么在JSP中跳轉(zhuǎn)到別一頁(yè)面...2006-10-10