Home  >  Forum  >  Java EE
Post New Query

How to Set Order of Filter in Servlet 3?



Asked on January 13, 2015
Hi All,

I am using @WebFilter to create filter in servlet 3. There is no element to set order of filter. How to set order?



Replied on January 14, 2015
We can not set order of filter using @WebFilter. We have to use web.xml to set order as below.

    <filter-mapping>
        <filter-name>filter1</filter-name>
        <url-pattern>/url/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>filter2</filter-name>
        <url-pattern>/url/*</url-pattern>
    </filter-mapping>
        <filter-mapping>
        <filter-name>filter3</filter-name>
        <url-pattern>/url/*</url-pattern>
    </filter-mapping>

And filter name is taken from

@WebFilter(filterName="filter1")
public class Filter1 implements Filter {
}

@WebFilter(filterName="filter2")
public class Filter2 implements Filter {
}

@WebFilter(filterName="filter3")
public class Filter3 implements Filter {
}



Hope it will help you.


Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us