Java component Filter

Source: Internet
Author: User

Introduction:
Similar to servlet, filter is a Java component. Before a request is sent to servlet, you can use the filter to intercept and process the request. After the servlet ends, you can also use the filter to process the response before sending the response back. The Web Container can use the web. xml deployment file to declare when to call the filter.
Note:
The filter also has a lifecycle: Init ()-> dofilter ()-> destroy ().
Example:
1. Java class
Public class encodingfilter extends httpservlet implements filter {
Private filterconfig;
// Initial Activation
Public void Init (filterconfig) throws servletexception {
This. filterconfig = filterconfig;
}
// Execute
Public void dofilter (servletrequest request, servletresponse response,
Filterchain ){
// The filtering method is written here.
}
// Destroy
Public void destroy (){
}
}
2. Web. xml configuration
<Filter>
<Filter-Name> encodingfilter </filter-Name>
<Filter-class> com. tongtech. bjvsp. sysmng. Filter. encodingfilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> encodingfilter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
As shown above, this is a simple filter.
References: http://www.javaeye.com/topic/82530

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.