This documentation is for WSO2 Carbon 4.4.7. View documentation for the latest release.
Filters - Carbon 4.4.7 - WSO2 Documentation
Skip to end of metadata
Go to start of metadata

A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), on the response from a resource, or both. Filters perform filtering in the doFilter method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, a reference to the ServletContext.

Sample Filter

public class MyFilter implements Filter {
 public void init(FilterConfig filterConfig) throws ServletException {

 public void destroy() {

 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
   throws IOException, ServletException {
  //Pre filter logic
  filterChain.doFilter(servletRequest, servletResponse);
                            //post filter logic

This filter can be added at product-level or application-level by updating the relevant web.xml file. See the sample given below. To enable this filter at product-level, add it to the <PRODUCT_HOME>/repository/conf/tomcat/web.xml file. To enable the filter for an individual application, you can add it to the web.xml in your application.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="" xmlns:xsi=""


The following filters are available in Carbon Kernel:

  • org.wso2.carbon.ui.filters.CSRFPreventionFilter

  • org.wso2.carbon.ui.filters.CRLFPreventionFilter

  • org.wso2.carbon.tomcat.ext.filter.CharacterSetFilter

  • No labels