Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpServlet cannot be resolved to a type .... is this a bug in eclipse? [duplicate]

Every thing was fine and i was able to run this JSP project, suddenly some thing happened and mostly all my servlets getting unresolved error.

I know its because specific JAR file cant be found for compilation.. but my "buildpath" is fine and i didnt make any changes..

I am stuck in this situation...

Tried

  1. cleaned project many times
  2. removes and added JRE library
  3. removed and added server(Tomcat 7.0.23)
like image 528
Jeba Prince Avatar asked Jan 03 '12 08:01

Jeba Prince


People also ask

What does it mean when something Cannot be resolved to a type?

"cannot be resolved to a type" means that the compiler has decided that, according to the syntax of the language, what it found at this place in the code has to be type, which means either a class, an interface, or a primitive tpye, but cannot find the definition of any type with that name.

Why my servlet is not working in Eclipse?

Add the server runtime to the web project to fix the HttpServlet not found Eclipse error. This will add all the JAR and ZIP files used by the servlet engine to the web project's runtime path. When this step is complete, rebuild the project and the HttpServlet not found Eclipse error message will go away.


1 Answers

You have to set the runtime for your web project to the Tomcat installation you are using; you can do it in the "Targeted runtimes" section of the project configuration.

In this way you will allow Eclipse to add Tomcat's Java EE Web Profile jars to the build path.

Remember that the HttpServlet class isn't in a JRE, but at least in an Enterprise Web Profile (e.g. a servlet container runtime /lib folder).

like image 160
Andrea Colleoni Avatar answered Sep 26 '22 19:09

Andrea Colleoni