Is there a way for a servlet filter to get a list of all servlets and their mappings?
There is no standard API (anymore; and what was there was rather limited) - but it's an XML file with a standard schema. You can obtain it in your filter via:
filterConfig.getServletContext().getResource("/WEB-INF/web.xml");
and get what you want from it using SAX / DOM / XPath / what have you, e.g.
InputStream is = filterConfig.getServletContext()
.getResourceAsStream("/WEB-INF/web.xml");
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document document = builder.parse(is);
NodeList servlets = document.getElementsByTagName("servlet");
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