Engine App NO CACHE JSP

I want to disable the cache for the JSP file on my google engine website.

I have it:

<% // Set to expire far in the past. response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT"); // Set standard HTTP/1.1 no-cache headers. response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // Set IE extended HTTP/1.1 no-cache headers (use addHeader). response.addHeader("Cache-Control", "post-check=0, pre-check=0"); // Set standard HTTP/1.0 no-cache header. response.setHeader("Pragma", "no-cache"); %> 

But JSP is still in cache. I need to kill a user session and log in again to reload the JSP code.

How to disable cache for the application JSP engine?

+4
source share
1 answer

At this point, it may be too late to change the response headers. They will simply be ignored. You can check for response headers in an HTTP debugger tool like Firebug .


alt text


In JSP, you need to make sure that they are set before the response is committed (i.e. all headers have already been sent, after which you cannot send other headers). That is, make sure that they are in the very top corner of the JSP file and that the template text is not located before this fragment of the scriptlet. The text of the template may cause the response to be committed. However, it is common practice to use Filter for this.

Deploy javax.servlet.Filter in which the doFilter() method looks like this:

 HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "no-cache", "no-store", "must-revalidate"); // HTTP 1.1 httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0 httpResponse.setDateHeader("Expires", 0); // Proxies. chain.doFilter(request, response); 

Map this in web.xml to url-pattern of *.jsp and it should work.

See also:

+3
source

Source: https://habr.com/ru/post/1307872/


All Articles