33

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)
MByD
  • 135,866
  • 28
  • 264
  • 277
Jeba Prince
  • 1,669
  • 4
  • 22
  • 41

6 Answers6

108

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

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Andrea Colleoni
  • 5,919
  • 3
  • 30
  • 49
  • Thank you so much it fixed it, but i have no idea why it just deselects "Targeted runtimes" on its own, when i was actually running the project – Jeba Prince Jan 03 '12 at 08:26
  • now i am getting a new error in consol from Tomcat "com.swiftant.jsp.LoginFilter cannot be cast to javax.servlet.Filter" – Jeba Prince Jan 03 '12 at 08:27
  • 1
    Check this: is com.swiftant.jsp.LoginFilter really an implementation of the right version of the javax.servlet.Filter? – Andrea Colleoni Jan 03 '12 at 08:34
  • sorry it was my fault i did ctrl+shift+O (lazy) it actually imported "import com.sun.org.apache.xalan.internal.xsltc.dom.Filter;" every thing works good as before thank you :) – Jeba Prince Jan 03 '12 at 08:39
  • I got this error even though my build path contained the tomcat 7 libs, i changed the order so that the tomcat is in the top in the order and export tab, rebuilt and it fixed it (might be some eclipse issue because when i moved the tomcat libs back to the bottom, it still worked fine) – thedrs Sep 15 '13 at 08:40
  • Thanx, was really helpful. "HttpServlet class isn't in a JRE" is great – timmz Mar 08 '15 at 17:45
1

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.

Dhaval Shah
  • 9,042
  • 2
  • 14
  • 21
1

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.

thomas88wp
  • 2,381
  • 19
  • 31
  • This is what worked for me. Apache Tomcat wasn't checked and as soon as I checked it, I stopped getting the error. Before doing this, I had to download and unpack Tomcat, and then add it as a server on Eclipse. – MicSokoli May 18 '17 at 12:14
0

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

Community
  • 1
  • 1
chammu
  • 1,275
  • 1
  • 18
  • 26
0

None of the recommendations I found on the web resolved for me, not even the ones here in this conversation.

The only thing that did resolve was uninstalling Tomcat 10 and installing version 9, then the issue was gone. I took this (http://tomcat.apache.org/whichversion.html) into account, but that didn't seem to have anything to do with my issue.

MarcosPS
  • 1
  • 1
  • Check [BalusC comment](https://stackoverflow.com/questions/8709528/httpservlet-cannot-be-resolved-to-a-type-is-this-a-bug-in-eclipse#comment53638034_8709528): the [cited answer](https://stackoverflow.com/q/4076601/11748454) explains your problem. Tomcat 10 uses the `jakarta.servlet` namespace instead of `javax.servlet`. – Piotr P. Karwasz Sep 29 '21 at 03:39
-2

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.

AJ.
  • 1,146
  • 11
  • 33
harika
  • 1