/**
*
*/
public class NoCacheFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpRes = (HttpServletResponse) response;
if (!httpReq.getRequestURI().startsWith(httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
httpRes.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
httpRes.setHeader("Pragma", "no-cache"); // HTTP 1.0.
httpRes.setDateHeader("Expires", 0); // Proxies.
}
chain.doFilter(request, response);
}
// ...
@Override
public void init(FilterConfig filterConfig) throws ServletException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void destroy() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
But it is not working, I still can get pages while pressing the forward and back buttons.
Please help.I have already cleared all the exsisting cache.
You should not purposefully throw exceptions during filter’s
init()anddestroy(). If theinit()throws an exception, then the filter is not placed in service and some servers will even completely abort the deploy of the webapp.They should do nothing if you have nothing to implement there.
You also need to make sure that the filter is mapped on the proper URL pattern or servlet name. Easiest is to put a
@WebFilter("Faces Servlet")on the class whereinFaces Servletis the exact servlet name of theFacesServletentry as you have inweb.xml.