37

I have imported a Java dynamic web project into the Eclipse IDE (which was implemented in Eclipse IDE and properly working).

I'm getting a "getDispatcherType() is undefined for the type HttpServletRequest" error while running the project.

I have copied every file into IDE as per the structure and the work is done.

Now I just want to know why I am getting this error when I have imported the project. Did anyone faced the same issue? Please let me know what mistake I might have made.

4
  • 1
    the project that was deployed in apache tomcat 7.0.X server version earlier. I tried to import that in my environment. I'm using apache tomcat 8.0.14 and I got above mentioned error. So i have changed my server to 7 version.My project working perfectly now. its not sounds logical. is apache tomcat is not reverse compatible!? Experts please clarify me. Oct 19, 2014 at 16:19
  • 2
    have you solved? Same problem here..
    – ianaz
    Oct 29, 2014 at 18:36
  • No, I have moved on from this issue. I'm using tomcat version 7.X. Nov 8, 2014 at 3:59
  • I had a library that was already included in Tomcat 8. I had to remove it from my project and then worked :) Can't remember which one was though...
    – ianaz
    Nov 10, 2014 at 10:02

6 Answers 6

42

I had the same issue when I had a conflicting servlet-api version I was using in IntelliJ that conflicted with what was supported in Tomcat 8.0.x... I was using Maven, so I just changed my dependency to this, then did a clean deploy of my webapp and the problem went away.

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
</dependency>
2
  • 1
    Hi, I am having the same issues. Just to clarify, did you add the 'provided' in the maven dependency?
    – Eyal Golan
    Dec 14, 2014 at 12:53
  • 3
    This is a wrong solution/fix, as you are adding the same dependency twice, one provided by tomcat 8, and another one in your lib folder. The error comes from adding servlet-api 2.5 from a third party dependency. Unless you are not in a container that provides you the servlet-api. Jun 24, 2015 at 14:22
14

tomcat 8.0.18, maven. It's about lib conflict. My solution is:

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
</dependency>

changed to:

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
</dependency>
6

You should exclude "servlet-api-2.5.jar" from any other dependency that you may have in your pom.xml.

Try not to add a different servlet-api as compile, as your tomcat already provides it for you.


My steps:

I have checked that there was a servlet-api-2.5.jar being included in my WEB-INF/lib folder by Maven, so then, I checked the full dependency graph on "Maven projects @IntelliJ Idea", then I excluded this dependency from ALL the places where it comes from. [ The button "Show dependencies" comes handy for this ]

I had to exclude "commons-logging" (as it has servlet-api 2.5 dependency) from velocity-tools. Also had to exclude servlet-api from jaxws-spring which has a direct dependency on default scope.

Then, just add the scope provided as you should on your javax.servlet-api dependency.

If you add your servlet-api 3.0.1+ as "compile", you may end up with both, and the first to load will win, which is not good at all.

Note: My guess is that this problem comes from the renaming of the groupId/artifactId of servlet-api, and not being overriden with the oldest version included on maven project. :\

1
  • You should probably accept this one. Worked for me by just commenting out: <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> Jul 2, 2015 at 12:52
1

I solved this problem by using the servlet-api.jar and jsp-api.jar from tomcat itself, so the dependency will be specified with system scope like below:

<servlet.api.jar.path>/opt/apache-tomcat-8.0.15/lib/servlet-api.jar</servlet.api.jar.path>
<jsp.api.jar.path>/opt/apache-tomcat-8.0.15/lib/jsp-api.jar</jsp.api.jar.path>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0</version>
        <scope>system</scope>
        <systemPath>${servlet.api.jar.path}</systemPath>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
        <scope>system</scope>
        <systemPath>${jsp.api.jar.path}</systemPath>
    </dependency>
1
  • I removed the jsp-api and jstl dependencies ( both were 2.1 and 1.2 versions) and it worked for me . Jun 20, 2015 at 12:37
1

If your tomcat is version 8 use:

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
</dependency>

worked!

1
  • this worked for me, tomcat 8 compatible solution!! Oct 6, 2016 at 1:38
0

This can also happen when upgrading from an old to newer Tomcat version and keeping the old jar files such as j2ee.jar and javaee.jar.

j2ee.jar should nerver be include in your webapp, the interfae is implemented by tomcat

Not the answer you're looking for? Browse other questions tagged or ask your own question.