'Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet

I am using eclipse neon.3 version and tomcat 8.5.15,I tried to execute simple hello world program using spring mvc but I am getting this issue=>

Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet.

It happened only with spring mvc projects,rather than spring mvc,other codes executed successfully. Also mentioned the jar files which I have uploaded. Please help me.

enter image description here



Solution 1:[1]

There is no javax.servlet-api.jar in the classpath. Maybe it is not in tomcat's lib folder. Try to add this jar to your WEB-INF/lib directory. To download a jar go to https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.1.0

Solution 2:[2]

I had the same problem when I first tried to use Tomcat. Since I used jakarta-servlet-api dependency I expected to find the HttpServlet class in a javax.servlet.http package, however I was wrong.
I extracted the jakarta-servlet-api.jar and saw that the package is called javax.
So I imported HttpServlet from javax.servlet.http instead and it worked fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jay Smith
Solution 2 catloverxx