Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:56:11+00:00 2026-05-23T14:56:11+00:00

If we define webapp specific servlet filters in WAR’s own web.xml , then the

  • 0

If we define webapp specific servlet filters in WAR’s own web.xml, then the order of execution of the filters will be the same as the order in which they are defined in the web.xml.

But, if we define those filters using @WebFilter annotation, what is the order of execution of filters, and how can we determine the order of execution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:56:12+00:00Added an answer on May 23, 2026 at 2:56 pm

    You can indeed not define the filter execution order using @WebFilter annotation. However, to minimize the web.xml usage, it’s sufficient to annotate all filters with just a filterName so that you don’t need the <filter> definition, but just a <filter-mapping> definition in the desired order.

    For example,

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

    with in web.xml just this:

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

    If you’d like to keep the URL pattern in @WebFilter, then you can just do like so,

    @WebFilter(filterName="filter1", urlPatterns="/url1/*")
    public class Filter1 implements Filter {}
    
    @WebFilter(filterName="filter2", urlPatterns="/url2/*")
    public class Filter2 implements Filter {}
    

    but you should still keep the <url-pattern> in web.xml, because it’s required as per XSD, although it can be empty:

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

    Regardless of the approach, this all will fail in Tomcat until version 7.0.28 because it chokes on presence of <filter-mapping> without <filter>. See also Using Tomcat, @WebFilter doesn't work with <filter-mapping> inside web.xml

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webapp in which I define the basic dispatcher-servlet context in web.xml
When creating/deploying war files, I use a in my web.xml to define which property
In a web application's web.xml file, one can define initial parameters for servlets and
I have a web app that lets a client define a daily rate for
I have a web app, I want to define my index.jsp file to be
Simple question really. Can a webapp access a config file I define and put
The App I need to implement a web app that will be used by
i have the following context.xml in webapp/META-INF/. This one is used by tomcat to
When using JAAS JDBCRealms with Tomcat, I usually define the realm in server.xml .
In an Dojo 1.7 AMD web app you can define also arbitrary data in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.