Say I have a J2EE filter. Say I want to do something in this filter, but conditionally, and depending on the servlet the request will end up hitting.
for example, I want a single filter that will prevent any non GET/POST request methods, but I have a few servlets that can deal with OPTIONS request method. So I if I knew what the target servlet was, and checked that it had some marker (i.e. interface or annotation) so that the filter can pass the OPTIONS request through (and otherwise return 405).
So far, the best I came up with is: request.getServletContext().getServletRegistration(request.getServletPath().substring(1)).getClassName()
(with proper NULL checks) gives me the class name of the servlet that the request will hit.