Search code examples
httpjspjstlcache-controlno-cache

Howto deactivate caching inside a jsp page


I understand there is a HTTP response header directive to disable page caching:

Cache-Control:no-cache

I can modify the header by "hand":

 <%response.addHeader("Cache-Control","no-cache");%>

But is there a "nice" way to make the JSP interpreter return this header line in the server response?

(I checked the <%@page ...%> directive. It seems there is nothing like that.)


Solution

  • Also add

    response.addHeader("Expires","-1");
    response.addHeader("Pragma","no-cache");
    

    to your headers and give that a shot.