Set a non-Cache Filter)

Source: Internet
Author: User

This seriesArticleGuidance:

Sessionfilter)

Set a non-Cache Filter)

Set the filter of the site blacklist (bannedaccessfilter)

Compressionfilter)

Stopwordsfilter)

Function Description

Set the cache parameter in the HTTP response header to no cache.

Usage

Add the following content to the Web. xml file of the Java Web project:Code.

<! -- Start with setting the filter that does not use the cache --> <filter-Name> abstrachefilter </filter-Name> <filter-class> COM. HMW. filter. abstrachefilter </filter-class> </filter> <filter-mapping> <filter-Name> abstrachefilter </filter-Name> <URL-pattern> *. DO </url-pattern> </filter-mapping> <filter-Name> abstrachefilter </filter-Name> <URL-pattern> *. JSP </url-pattern> </filter-mapping> <! -- Set the end of the filter configuration that does not use the cache -->
Filter source code
Package COM. HMW. 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;/*** filters that prevent the browser from caching page information
* Creation date: 2012-01-10 ** @ author he mingwang */public class implements achefilter implements filter {@ override public void Init (filterconfig) throws servletexception {}@ override public void dofilter (servletrequest request, servletresponse response, filterchain) throws ioexception, servletexception {response httpresponse = (response) response; httpresponse. setheader ("cache-control", "No-Cache"); httpresponse. setheader ("Pragma", "No-Cache"); httpresponse. setdateheader ("expires",-1); filterchain. dofilter (request, response) ;}@ override public void destroy (){}}

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.