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");
//指定该页面不缓存
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);
}
}
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");
//指定该页面不缓存
//response.setDateHeader("Expires",-1); //IE游览器支持的
//缓存一定的时间 缓存 一天的时间
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);
}
}