Java Qiao Xiaosong-Clear the webpage cache using the filter Filter

Source: Internet
Author: User
Package www. csdn. dbshop. filter; 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. httpservletresponse; public class cachefilter implements filter {public void destroy () {system. out. println ("cache filter ------ destruction operation");} public void dofilter (servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception {system. out. println ("Clear cache ................ "); // response object httpservletresponse res = (httpservletresponse) response; // set the expiration time of the webpage. Once it expires, you must call res again on the server. setdateheader ("expires",-1); // cache-control specifies the cache mechanism that the request and response should follow. No-Cache indicates that the request or response message cannot be cached by Res. setheader ("cache-control", "No-Cache"); // used to disable the browser from calling the page content from the local cache, once the page is set, Res cannot be called out from the cache. setheader ("Pragma", "No-Cache"); // release the chain. dofilter (request, Res);} public void Init (filterconfig) throws servletexception {system. out. println ("initialize data ----- clear cache ");}}

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.