4

How to exclude particular format of URL from the filter?

Is there a standard method or alternative solution ?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
HarshaKP
  • 159
  • 3
  • 12
  • 1
    Possible duplicate of [Can I exclude some concrete urls from inside ?](http://stackoverflow.com/questions/3125296/can-i-exclude-some-concrete-urls-from-url-pattern-inside-filter-mapping) – beat Feb 10 '17 at 15:41

1 Answers1

6

This isn't possible via <url-pattern> configuration.

You've basically 2 options:

  1. Make <url-pattern> more specific. E.g. move all those resources wich really need to be filtered in a specific folder like /app and set the <url-pattern> to /app/*. Then you can just put the excluded page outside that folder.

  2. Check for the request URI in the filter and just continue the chain if it represents the excluded page.

    E.g.

    String loginURL = request.getContextPath() + "/login.jsp";
    
    if (request.getRequestURI().equals(loginURL)) {
        chain.doFilter(request, response);
    }
    else {
        // ...
    }
    
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555