Rectangle 27 0

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()LjavalangString;?


  • Make sure that the root declaration of web.xml complies Servlet 2.5 (or newer, at least the highest whatever your target runtime supports). For an example, see also somewhere halfway our servlets wiki page.
  • Make sure that you don't have any servlet container specific libraries like servlet-api.jar or j2ee.jar in /WEB-INF/lib or even worse, the JRE/lib or JRE/lib/ext. They do not belong there. This is a pretty common beginner's mistake in an attempt to circumvent compilation errors in an IDE, see also How do I import the javax.servlet API in my Eclipse project?.
  • The servlet container does not support Servlet 2.5.
  • The web.xml is not declared conform Servlet 2.5 or newer.
  • The webapp's runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which does not support Servlet 2.5.

In my case, another dependency (Axis2) was loading servlet-api 2.3. Putting Axis2 at the end of my dependencies in pom.xml solved the problem. Tnx!

Note
Rectangle 27 0

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()LjavalangString;?


  • Make sure that the root declaration of web.xml complies Servlet 2.5 (or newer, at least the highest whatever your target runtime supports). For an example, see also somewhere halfway our servlets wiki page.
  • Make sure that you don't have any servlet container specific libraries like servlet-api.jar or j2ee.jar in /WEB-INF/lib or even worse, the JRE/lib or JRE/lib/ext. They do not belong there. This is a pretty common beginner's mistake in an attempt to circumvent compilation errors in an IDE, see also How do I import the javax.servlet API in my Eclipse project?.
  • The servlet container does not support Servlet 2.5.
  • The web.xml is not declared conform Servlet 2.5 or newer.
  • The webapp's runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which does not support Servlet 2.5.

In my case, another dependency (Axis2) was loading servlet-api 2.3. Putting Axis2 at the end of my dependencies in pom.xml solved the problem. Tnx!

Note
Rectangle 27 0

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()LjavalangString;?


  • Make sure that the root declaration of web.xml complies Servlet 2.5 (or newer, at least the highest whatever your target runtime supports). For an example, see also somewhere halfway our servlets wiki page.
  • Make sure that you don't have any servlet container specific libraries like servlet-api.jar or j2ee.jar in /WEB-INF/lib or even worse, the JRE/lib or JRE/lib/ext. They do not belong there. This is a pretty common beginner's mistake in an attempt to circumvent compilation errors in an IDE, see also How do I import the javax.servlet API in my Eclipse project?.
  • The servlet container does not support Servlet 2.5.
  • The web.xml is not declared conform Servlet 2.5 or newer.
  • The webapp's runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which does not support Servlet 2.5.

Are there any more than these 3? I am suddenly getting this message after yum auto-updated from tomcat 6.0.35 to 6.0.36. None of the webapps or jars have changed as far as the logs show...

Good answer, only point 2 is not correct. At least with Spring, if you don't declare Servlet 2.5 in your web.xml, but instead use 2.4 or before, there won't be Servlet 2.5-specific code executed, so you can't get the OP's error.

I had the servlet 3.0.1 declared in my pom but another dependency had a transitive one on servlet-api-2.4. I exclueded the 2.4 version and everything worked.

In my case, another dependency (Axis2) was loading servlet-api 2.3. Putting Axis2 at the end of my dependencies in pom.xml solved the problem. Tnx!

Note
Rectangle 27 0

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()LjavalangString;?


  • Make sure that the root declaration of web.xml complies Servlet 2.5 (or newer, at least the highest whatever your target runtime supports). For an example, see also somewhere halfway our servlets wiki page.
  • Make sure that you don't have any servlet container specific libraries like servlet-api.jar or j2ee.jar in /WEB-INF/lib or even worse, the JRE/lib or JRE/lib/ext. They do not belong there. This is a pretty common beginner's mistake in an attempt to circumvent compilation errors in an IDE, see also How do I import the javax.servlet API in my Eclipse project?.
  • The servlet container does not support Servlet 2.5.
  • The web.xml is not declared conform Servlet 2.5 or newer.
  • The webapp's runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which does not support Servlet 2.5.

Are there any more than these 3? I am suddenly getting this message after yum auto-updated from tomcat 6.0.35 to 6.0.36. None of the webapps or jars have changed as far as the logs show...

Good answer, only point 2 is not correct. At least with Spring, if you don't declare Servlet 2.5 in your web.xml, but instead use 2.4 or before, there won't be Servlet 2.5-specific code executed, so you can't get the OP's error.

I had the servlet 3.0.1 declared in my pom but another dependency had a transitive one on servlet-api-2.4. I exclueded the 2.4 version and everything worked.

In my case, another dependency (Axis2) was loading servlet-api 2.3. Putting Axis2 at the end of my dependencies in pom.xml solved the problem. Tnx!

Note
Rectangle 27 0

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()LjavalangString;?


  • Make sure that the root declaration of web.xml complies Servlet 2.5 (or newer, at least the highest whatever your target runtime supports). For an example, see also somewhere halfway our servlets wiki page.
  • Make sure that you don't have any servlet container specific libraries like servlet-api.jar or j2ee.jar in /WEB-INF/lib or even worse, the JRE/lib or JRE/lib/ext. They do not belong there. This is a pretty common beginner's mistake in an attempt to circumvent compilation errors in an IDE, see also How do I import the javax.servlet API in my Eclipse project?.
  • The servlet container does not support Servlet 2.5.
  • The web.xml is not declared conform Servlet 2.5 or newer.
  • The webapp's runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which does not support Servlet 2.5.

Are there any more than these 3? I am suddenly getting this message after yum auto-updated from tomcat 6.0.35 to 6.0.36. None of the webapps or jars have changed as far as the logs show...

Good answer, only point 2 is not correct. At least with Spring, if you don't declare Servlet 2.5 in your web.xml, but instead use 2.4 or before, there won't be Servlet 2.5-specific code executed, so you can't get the OP's error.

I had the servlet 3.0.1 declared in my pom but another dependency had a transitive one on servlet-api-2.4. I exclueded the 2.4 version and everything worked.

In my case, another dependency (Axis2) was loading servlet-api 2.3. Putting Axis2 at the end of my dependencies in pom.xml solved the problem. Tnx!

Note