Java prohibits the browser from caching the source code. java prohibits the caching of the source code.

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.