D
D
Denis Kuznetsov2020-07-22 15:48:05
Java
Denis Kuznetsov, 2020-07-22 15:48:05

How to call a method on a ServletContext object?

Hello, in many examples I saw how the following code is present for the authentication filter settings

   private static boolean hasUrlPattern(ServletContext servletContext, String urlPattern) {
 
      Map<String, ? extends ServletRegistration> map = servletContext.getServletRegistrations();

But for some reason, when I create an object of the ServletContext class, I cannot find the given getServletRegistrations() method for it; , do not tell me how to get the necessary map, thank you

5f1868b5120f4406708285.jpeg

5f1868c5a4eb4588015575.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Kuznetsov, 2020-07-23
@DennisKingsman

Solution found, I used too old versions

javaee-api
and
javax.servlet-api
the first one had a version below 8th and the second one had a version below 3rd,
if you change the dependencies in pom.xml to the following, then all functions will be found
<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question