最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JSP 開(kāi)發(fā)之Servlet解決網(wǎng)頁(yè)緩存問(wèn)題

 更新時(shí)間:2017年08月01日 17:31:47   投稿:lqh  
這篇文章主要介紹了JSP 開(kāi)發(fā)之Servlet解決網(wǎng)頁(yè)緩存問(wèn)題的相關(guān)資料,原理在不需要緩存的頁(yè)面中需要實(shí)現(xiàn)不緩存頁(yè)面,需要的朋友可以參考下

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ì)本站的支持!

相關(guān)文章

最新評(píng)論

南昌县| 漠河县| 嘉定区| 中山市| 神池县| 丰城市| 喀喇沁旗| 盐山县| 米林县| 错那县| 东辽县| 漠河县| SHOW| 北碚区| 叶城县| 鄄城县| 兴海县| 武汉市| 车致| 宝兴县| 兴化市| 阳山县| 深州市| 永泰县| 临安市| 滨海县| 会昌县| 灵川县| 芜湖市| 平和县| 高碑店市| 通州区| 建始县| 原阳县| 松阳县| 华容县| 南昌县| 忻州市| 高台县| 甘孜| 古丈县|