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");
}
Update the filter seems to be 3rd party API (you should have mentioned that in your question). In that case, map it on a more specific url-pattern
, e.g. /otherfilterpath/*
and let your filter which is listening on /*
forward to that.
String path = ((HttpServletRequest) request).getRequestURI();
if (path.startsWith("/specialpath")) {
chain.doFilter(request, response); // Just continue chain.
} else {
request.getRequestDispatcher("/otherfilterpath" + path).forward(request, response);
}
Update 2: oh, I almost forget to add, 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.