The following code accesses a servlet’s name: servletConfig.getServletName().
Can I access a servlet’s URL pattern in a similar way?
An excerpt from web.xml:
<servlet-mapping>
<servlet-name>This is the servlet's name</servlet-name>
<url-pattern>/this-is-its-url-pattern/*</url-pattern>
</servlet-mapping>
Nothing is available in the Servlet API. Either parse the
web.xmlyourself, or duplicate it as an<init-param>of the servlet wherein you’d like to access it.This way it’s available by
servletConfig.getInitParameter("url-pattern").