0

I am starting on web-security and I have to control the cache on the portal, this portal has many urls. I understand that I need to set the header with this:

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

But my question is: The code above is valid for all the urls that I want to controling (You know the cache) or how I set this attribute for all the urls or for a url in specific?.

Erik
  • 503
  • 1
  • 7
  • 26
Rock Pz
  • 3
  • 1
  • Hi Yohannes Gebremariam: I meant the urls belong to the main portal, ie the main url is [example.com] and the "other" urls are [example.com/another_url] and [example.com/this_is_another_url] and I want to control the cache of the 3 urls above. how can I control the cache for all of them?, thanks in advance – Rock Pz Jun 05 '18 at 21:19

2 Answers2

0

Put this code in a web filter and map the filter to all the urls where you want to disable caching.

gagan singh
  • 1,591
  • 1
  • 7
  • 12
  • What code? by the way: I meant the urls belong to the main portal, ie the main url is [example.com] and the "other" urls are [example.com/another_url] and [example.com/this_is_another_url] and I want to control the cache of the 3 urls above. how can I control the cache for all of them?, thanks in advance – Rock Pz Jun 05 '18 at 23:19
0

Assuming you have access to both request and response objects. You can use one of the following methods of HttpRequest object in your control method to set those response parameters

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

I mean something like this

if(request.getRequestURL().equals("http://someurl"))
{
//do your stuff
}
Yohannes Gebremariam
  • 2,225
  • 3
  • 17
  • 23
  • Hi Yohannes Gebremariam: I meant the urls belong to the main portal, ie the main url is [example.com] and the "other" urls are [example.com/another_url] and [example.com/this_is_another_url] and I want to control the cache of the 3 urls above. how can I control the cache for all of them?, thanks in advance – Rock Pz Jun 05 '18 at 21:28