Search code examples
javahtmlwebsecurity

How to set the Cache-Contro for many urls


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?.


Solution

  • 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
    }