0

Here is my Eclipse-wide JRE definition clearly showing the servlet-api.jar has been added:

enter image description here

And here are the same old import errors that just never seem to be able to be resolved. Isn't Java awesome? Any chance someone has a simple, factual answer as to why this still doesn't work?

enter image description here

Jimmy D
  • 5,282
  • 16
  • 54
  • 70
  • The project says it is using JavaSE-11 execution environment - is that set to be using the Java 17? – greg-449 Nov 28 '21 at 11:58
  • Shouldn't you include Tomcat libraries as a normal library instead of a JRE? Sorry haven't used Eclipse in centuries. – m0skit0 Nov 28 '21 at 12:00
  • Are you not able to add Tomcat server library onto the build path? Please do try and update - Right-click on project -> Build Path -> Configure Build Path... -> Libraries (tab) -> Select Classpath -> Add Library -> Server Runtime -> Select the one you must have added for Tomcat 10. – Sree Kumar Nov 28 '21 at 12:17
  • If you haven't set up Tomcat server runtime, then Windows -> Preferences -> Server -> Runtime Environments -> Add. – Sree Kumar Nov 28 '21 at 12:18
  • 1
    You're using the servlet JAR of Tomcat 10, which uses JakartaEE 9, which switched from the `javax.*` package namespace to `jakarta.*` package namespace. Either downgrade to Tomcat 9, or make sure you use the new JakartaEE 9 package names. – Mark Rotteveel Nov 28 '21 at 17:31

1 Answers1

3

jakarta.servlet versus javax.servlet

Any chance someone has a simple, factual answer as to why this still doesn't work?

Because:

And your code is trying to use the old package name.

Solutions:

  1. Change your webapp code to import from the new jakarta.servlet package, OR
  2. Roll back to a version of Tomcat that supports the older version of the Servlet spec; i.e. Tomcat 9.0.x or earlier.
nitind
  • 19,089
  • 4
  • 34
  • 43
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216