有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Lastmodified标头在第二次刷新后不工作

若并没有更改,我想从缓冲区加载photourl,但它只有在第一次刷新页面后才能工作。当我第一次打开页面时,这是我的回应

Cache-Control no-cache
Content-Length 12279
Content-Type text/plain
Date Thu, 18 Aug 2016 10:26:45 GMT
Expires Mon, 01 Jan 1990 00:00:00 GMT
Last-Modified Thu, 18 Aug 2016 09:56:55 GMT
Server Development/1.0

刷新后,我有304个状态和响应:

Cache-Control no-cache, no-store, max-age=0, must-revalidate
Date Thu, 18 Aug 2016 10:29:21 GMT
Expires 0
Last-Modified Thu, 18 Aug 2016 09:56:55 GMT
Pragma no-cache
Server Development/1.0
X-Frame-Options DENY
X-XSS-Protection 1; mode=block
x-content-type-options nosniff

应要求

If-Modified-Since Thu, 18 Aug 2016 09:56:55 GMT

在另一次刷新后,我有200个状态,就像第一次访问一样,数据从服务器重新加载

这是我的控制器

@ResponseBody
@RequestMapping(value = "/photo", produces = "text/plain", method = RequestMethod.GET)
public String myPhoto(HttpServletResponse response, WebRequest request) {

    Photo photo = photoService.getPhoto();

    long lastModified = photo.getModificationDate().getTime();
            if (request.checkNotModified(lastModified)) {
              return null;
            }
            return photo.photoURL();            

}

共 (0) 个答案