Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getDispatcherType() is undefined for the type HttpServletRequest [duplicate]

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.

like image 203
no_lyf_programmer Avatar asked Oct 18 '14 05:10

no_lyf_programmer


3 Answers

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>
like image 95
James Boutcher Avatar answered Oct 23 '22 14:10

James Boutcher


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>
like image 14
zond Avatar answered Oct 23 '22 14:10

zond


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. :\

like image 6
Juan Carrey Avatar answered Oct 23 '22 15:10

Juan Carrey