Java prohibits the browser from caching the source code. java prohibits the caching of the source code.
Java prohibits the browser from having cached source code
Import java. io. IOException; import javax. servlet. filter; import javax. servlet. filterChain; import javax. servlet. filterConfig; import javax. servlet. servletException; import javax. servlet. servletRequest; import javax. servlet. servletResponse; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import org. slf4j. logger; import org. slf4j. loggerFactory;/***** force not to cache pages for mutual E-Commerce Learning Exchange Group: 168096884 * @ author */public class ForceNoCacheFilter implements Filter {private static final Logger logger = LoggerFactory. getLogger (ForceNoCacheFilter. class); @ Override public void doFilter (ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {logger.info ("[ForceNoCacheFilter] start ...... "); HttpServletResponse response = (HttpServletResponse) resp; HttpServletRequest request = (HttpServletRequest) req; String url = request. getRequestURI (); logger.info ("[ForceNoCacheFilter] [web client request] [url]" + url); response. setHeader ("Cache-Control", "no-cache"); response. setHeader ("Pragma", "no-cache"); response. setDateHeader ("Expires",-1); filterChain. doFilter (req, resp); return ;}@ Override public void init (FilterConfig filterConfig) throws ServletException {logger.info ("[ForceNoCacheFilter] system initialization init ...... ") ;}@ Override public void destroy () {logger.info (" [ForceNoCacheFilter] destroy ...... ");}}
At the same time, do not forget to configure web. xml ..
<Filter>
<Filter-name> NoCacheFilter </filter-name>
<Filter-class> com. xx. filter. ForceNoCacheFilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-name> NoCacheFilter </filter-name>
<Url-pattern> *. jsp </url-pattern>
</Filter-mapping>
Learning: I spent more time with you.