Home  >  Forum  >  Java EE
Post New Query

How to Set Order of Filter in Servlet 3?


joined on
November 02,2014
Asked on January 14,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?
joined on
October 10,2013
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








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us