我需要强制浏览器从 URL 加载 Web 资源,而不是从浏览器缓存加载。如何在 Jersey 中设置 Pragma: no-cache
HTTP header 回应?
代码:
@GET @Path("/cache/{id}")
@Produces({"application/json"})
public static String getCachachedJSON(@PathParam("id") int id) {
return getJSONRecord(id);
}
更新:
通过实现ContainerResponseFilter
并重写filter
方法解决。
最佳答案
将响应添加为@Context
资源,它也可以是参数或字段:
getCachachedJSON(@PathParam("id") int id, @Context HttpServletResponse servletResponse)
然后使用addHeader
函数:
servletResponse.addHeader("Pragma", "no-cache");
关于java - 如何设置Pragma : no-cache HTTP header in Jersey?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25784563/