//當訪問一些資源文件時,咱們但願,訪問一次後,資源文件可以在緩存在瀏覽器中,當咱們再次訪問該資源時java
//直接從緩存中去取,這樣能夠減小服務器的壓力瀏覽器
package response;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ResponseDemo6 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//設置頭信息,控制瀏覽器緩存
response.setDateHeader("expires",System.currentTimeMillis()+1000*3600);//時間值必定得是當前時間值加上要緩存的時間
//模擬場景
String data = "aaaaa";
response.getWriter().write(data);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
緩存