package test.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 ResponseDemo5 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 发送缓存头,缓存时间是从1970年开始的,要先得到当前时间然后+想要缓存的时间,是毫秒单位的
response.setDateHeader("expries",
System.currentTimeMillis() + 1000 * 3600);
String date = "aaaaaaaaaaaa";
response.getWriter().write(date);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
javaweb之response用Expires头控制浏览器使用缓存
最新推荐文章于 2023-04-10 14:42:05 发布