Is there a way to specify negative mappings in web.xml? For example, I want to set a filter for ALL requests EXCEPT those matching '/public/*'.
No, that's not possible. You'd have to do the URL pattern matching yourself inside the doFilter() method. Map the filter on /* and do the following job:
HttpServletRequest req = (HttpServletRequest) request;
if (req.getRequestURI().startsWith("/public/")) {
chain.doFilter(request, response);
return;
}
// ...
or when there's actually a context path:
HttpServletRequest req = (HttpServletRequest) request;
if (req.getRequestURI().startsWith(req.getContextPath() + "/public/")) {
chain.doFilter(request, response);
return;
}
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With