I have this configuration in web.xml fileof my Java EE Web application:
<servlet-mapping>
<servlet-name>ChangeLanguageServlet</servlet-name>
<url-pattern>/change</url-pattern>
</servlet-mapping>
What I want to do is get the String of "url-pattern" using the servlet-name, something like this (pseudocode):
// This would return "/change"
String pattern = getPatternByServletName("ChangeLanguageServlet");
I don't know how to do it.
Any help?
Thanks!
From the
ServletContext
you can get aMap
keyed by servlet name with all servlets registered in the application:Then use the
ServletRegistration
API to extract the metadata you need, including: