HttpServlet---getLastModified与缓存
来源:互联网 发布:sql截取指定字符前面 编辑:程序博客网 时间:2024/04/30 18:56
今天看HttpServlet源码看到一个函数getLastModified,上网查阅与浏览器缓存有关系,根据源码,画了个流程图理解下:
源码:
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String method = req.getMethod(); if (method.equals(METHOD_GET)) { long lastModified = getLastModified(req); if (lastModified == -1) { // servlet doesn't support if-modified-since, no reason // to go through further expensive logic doGet(req, resp); } else { long ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE); if (ifModifiedSince < lastModified) { // If the servlet mod time is later, call doGet() // Round down to the nearest second for a proper compare // A ifModifiedSince of -1 will always be less maybeSetLastModified(resp, lastModified); doGet(req, resp); } else { resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } } } }
最后的结果为只有当request中存储的服务器上次告诉它的最后修改时间比服务器端request的修改时间later时,服务器会响应304状态码,浏览器解析该状态码,明白请求并未改变,启用浏览器中缓存的数据。
0 0
- HttpServlet---getLastModified与缓存
- 浏览器缓存内幕与getLastModified方法
- 浏览器缓存内幕与getLastModified方法
- 浏览器缓存内幕与getLastModified方法
- getLastModified()方法和浏览器缓存
- 关于浏览器的缓存和getLastModified()的使用问题。
- 关于浏览器的缓存和getLastModified()的使用问题
- servlet getLastModified
- HTTP与HttpServlet
- HTTP与HttpServlet
- day05-GenericServlet与HttpServlet
- HTTP与HttpServlet
- Servlet与HttpServlet
- HtttpServlet Request 与 HttpServlet Response
- HttpServlet
- HTTPServlet
- HttpServlet
- httpServlet
- RESTful API的安全性常用方法
- iOS开发之封装水平菜单栏
- 32位plsql连接64位Oracle
- 『java.lang.util』-- collection 接口研究
- java中mysql问题
- HttpServlet---getLastModified与缓存
- Java使用JWS API开发Web Service
- 关于 raw和assets两个文件的区别
- post 和 get 的区别
- Ubuntu下安装nginx常见问题及解决办法
- Eclipse下导入外部jar包的3种方式
- java.lang.SecurityException: Not allowed to bind to service Intent 不允许绑定服务
- CVPapers - Computer Vision Resource
- C++ const