HttpServlet cannot be resolved to a type … is this a bug in eclipse?

后端 未结 5 543
别跟我提以往
别跟我提以往 2020-12-28 14:19

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 sp

相关标签:
5条回答
  • 2020-12-28 14:33

    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).

    0 讨论(0)
  • 2020-12-28 14:40

    A simple solution for me was to go to Properties -> Java Build Path -> Order and Export, then check the Apache Tomcat library. This is assumes you've already set Tomcat as your deployment target and are still getting the error.

    0 讨论(0)
  • 2020-12-28 14:43

    It happened for me also and the reason was selecting inappropriate combination of tomcat and Dynamic web module version while creating project in eclipse. I selected Tomcat v9.0 along with Dynamic web module version 3.1 and eclipse was not able to resolve the HttpServlet type. When used Tomcat 7.0 along with Dynamic web module version 7.0, eclipse was automatically able to resolve the HttpServlet type.

    Related question Dynamic Web Module option in Eclipse

    To check which version of tomcat should be used along with different versions of the Servlet and JSP specifications refer http://tomcat.apache.org/whichversion.html

    0 讨论(0)
  • 2020-12-28 14:44

    It means that servlet jar is missing .

    check the libraries for your project. Configure your buildpath download **

    servlet-api.jar

    ** and import it in your project.

    0 讨论(0)
  • 2020-12-28 14:45

    I faced the same problem in eclipse with tomcat7 with the error javax.servlet cannot be resolved. If I select the server in targeted runtime mode and build project again, the error get's resolved.

    0 讨论(0)
提交回复
热议问题