简体   繁体   中英

eclipse servlet java.lang.ClassNotFoundException: javax.servlet.Servlet

I keep getting this error: java.lang.ClassNotFoundException: javax.servlet.Servlet when I attempt to run my servlet in eclipse.

I am using the web version of eclipse in conjunction with Tomcat. I have servlet-api.jar in the library, as well as javaee-6.0.jar imported (though I believe I am using java 7, this was the most recent version of this I could find)

在此输入图像描述

So why do I keep getting this error? I've scoured the web and the solution has always been servlet-api.jar, but I have this file in the library to no benefit.

Thank you in advance!

Is that error happing during the compilation or during the run?

Did you configure Eclipse to point to the Tomcat server? In order to run a web server in eclipse using tomcat, you need to tell eclipse about tomcat first. Here is where you ca find the instruction. http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

Even though you have your servlet-api.jar you most probably dont need to bundle it with your war. Generally tomcat uses it own servlet-api, which is located ./common/lib/servlet-api.jar.

Most probably you are missing this, which causes the ClassNotFoundException

You correctly have added servlet.jar and javaee.jar. The error you specified is typically happens when one of those two files are missing. However, since you have those files, I recommend doing the following:

  • Removed the jar files and add them back in to your project 在此输入图像描述
  • Once you added them back in then do a clean build 在此输入图像描述
  • If none of the above steps fixes your problem then try creating a new web application and add all of your jar files again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM