欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)論