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 908957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:47:56+00:00 2026-05-15T16:47:56+00:00

I want some concrete filter to be applied for all urls except for one

  • 0

I want some concrete filter to be applied for all urls except for one concrete (i.e. for /* except for /specialpath).

Is there a possibility to do that?


sample code:

<filter>
    <filter-name>SomeFilter</filter-name>
    <filter-class>org.somproject.AFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SomeFilter</filter-name>
    <url-pattern>/*</url-pattern>   <!-- the question is: how to modify this line?  -->
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
  • 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-15T16:47:57+00:00Added an answer on May 15, 2026 at 4:47 pm

    The standard Servlet API doesn’t support this facility. You may want either to use a rewrite-URL filter for this like Tuckey’s one (which is much similar Apache HTTPD’s mod_rewrite), or to add a check in the doFilter() method of the Filter listening on /*.

    String path = ((HttpServletRequest) request).getRequestURI();
    if (path.startsWith("/specialpath/")) {
        chain.doFilter(request, response); // Just continue chain.
    } else {
        // Do your business stuff here for all paths other than /specialpath.
    }
    

    You can if necessary specify the paths-to-be-ignored as an init-param of the filter so that you can control it in the web.xml anyway. You can get it in the filter as follows:

    private String pathToBeIgnored;
    
    public void init(FilterConfig config) {
        pathToBeIgnored = config.getInitParameter("pathToBeIgnored");
    }
    

    If the filter is part of 3rd party API and thus you can’t modify it, then map it on a more specific url-pattern, e.g. /otherfilterpath/* and create a new filter on /* which forwards to the path matching the 3rd party filter.

    String path = ((HttpServletRequest) request).getRequestURI();
    if (path.startsWith("/specialpath/")) {
        chain.doFilter(request, response); // Just continue chain.
    } else {
        request.getRequestDispatcher("/otherfilterpath" + path).forward(request, response);
    }
    

    To avoid that this filter will call itself in an infinite loop you need to let it listen (dispatch) on REQUEST only and the 3rd party filter on FORWARD only.

    See also:

    • How to prevent static resources from being handled by front controller servlet which is mapped on /*
    • How to handle static content in Spring MVC?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want some particular urls like springer.com to automatically convert to springer.com.proxy1.mycollege.edu. The second
I want some code to be triggered every second. Usually, I'd create a Timer
This is a more concrete question that is connected with my previous one. I
I'm trying to do some parameter estimation and want to choose parameter estimates that
I want to return an array that that maps some filtered elements - but
I want to write a method in Java that verifies that some conditions hold
I want some slightly 'dynamic' XML source files. I want some of the element
I want some of the items to be bold depending on a property of
I want some examples of C preprocessor directives, such as: #define pi 3.14 #define
I want some of the goodies in a ListView, like being able to use

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.