【问题标题】:How to set the Cache-Contro for many urls如何为多个 url 设置 Cache-Control
【发布时间】:2018-11-15 08:06:20
【问题描述】:

我从网络安全开始,我必须控制门户上的缓存,这个门户有很多网址。我知道我需要用这个设置标题:

  response.setHeader("Cache-Control","no-cache,no-store,must-revalidate");
  response.setHeader("Pragma", "no-cache");

但我的问题是:上面的代码对我想要控制的所有 url 都有效(你知道缓存)或者我如何为所有 url 或特定的 url 设置此属性?。

【问题讨论】:

  • 嗨 Yohannes Gebremariam:我的意思是网址属于主门户,即主网址是 [example.com],“其他”网址是 [example.com/another_url] 和 [example.com]。 com/this_is_another_url] 我想控制上面 3 个 url 的缓存。我怎样才能控制所有的缓存?提前谢谢

标签: java html websecurity


【解决方案1】:

假设您可以访问请求和响应对象。您可以在控制方法中使用 HttpRequest 对象的以下方法之一来设置这些响应参数

 - getPathInfo()
 - getRequestURL()
 - getRequestURI() 

我的意思是这样的

if(request.getRequestURL().equals("http://someurl"))
{
//do your stuff
}

【讨论】:

  • 嗨 Yohannes Gebremariam:我的意思是网址属于主门户,即主网址是 [example.com],“其他”网址是 [example.com/another_url] 和 [example.com]。 com/this_is_another_url] 我想控制上面 3 个 url 的缓存。我怎样才能控制所有的缓存?提前谢谢
【解决方案2】:

将此代码放入网络过滤器并将过滤器映射到您要禁用缓存的所有网址。

【讨论】:

  • 什么代码?顺便说一句:我的意思是网址属于主门户,即主网址是 [example.com],“其他”网址是 [example.com/another_url] 和 [example.com/this_is_another_url],我想控制上面3个url的缓存。我怎样才能控制所有的缓存?提前谢谢
猜你喜欢
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 2016-05-24
  • 2019-01-20
  • 2020-12-03
  • 1970-01-01
  • 2019-05-21
  • 1970-01-01
相关资源
最近更新 更多