//当访问一些资源文件时,咱们但愿,访问一次后,资源文件可以在缓存在浏览器中,当咱们再次访问该资源时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);
}
}
缓存