Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"javax.servlet.http.HttpServlet" was not found on the Java Build Path [duplicate]

Tags:

java

eclipse

jsp

I am just trying to learn some JSP but I am getting that error repeatedly. I've tried everything on the internet and nothing happened. I am using the Tomcat v10 and JDK15.0.2. This error occurs when I create a new JSP file. enter image description here

like image 567
ghostcasper Avatar asked Feb 08 '21 21:02

ghostcasper


People also ask

How to fix the HttpServlet not found error in Eclipse?

1. Add Target Server Runtime. In this solution, you can add desired server runtime into your application as a project facet. As runtime servers have already servlet runtime dependencies, they get included in your project and hence the error is gone.

What is javax servlet HttpServlet?

An abstract class that simplifies writing HTTP servlets. It extends the GenericServlet base class and provides an framework for handling the HTTP protocol. Because it is an abstract class, servlet writers must subclass it and override at least one method.


2 Answers

Java EEJakarta EE

Read the front page of downloading documentation for Apache Tomcat 10. To quote:

Users of Tomcat 10 onwards should be aware that, as a result of the move from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.* to jakarta.*. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.

And read the first page of the main documentation for Apache Tomcat 10. To quote:

Apache Tomcat version 10.0 implements the Servlet 5.0 and JavaServer Pages 3.0 specifications from Jakarta EE …

As part of Oracle turning over responsibility for what was known as Java EE (Enterprise Edition) to the Eclipse Foundation, the package names in Jakarta EE are changing from javax.* to jakarta.*. You can read about this on the Tomcat page, Which version? — Apache Tomcat Versions, and on the internet.

  • Tomcat 10 is for people moving forward to Jakarta EE versions 9 and later, using the jakarta.* namespace with the latest Servlet & JSP specs.
  • Tomcat 9 is for people sticking with the javax.* namespace using the popular Servlet 4 spec and related APIs.

If you want to use the latest APIs, change your import statements to use jakarta. rather than javax.. Or switch out your Tomcat 10 for Tomcat 9 to use the older javax. namespace.

  • If you are learning and experimenting, I suggest using the jakarta. namespace along with Tomcat 10.
  • If you are using important libraries or tools that are not yet updated to the jakarta. namespace, stick with the older APIs and Tomcat 9.

There has been talk of tools to help by automating some of this namespace switch. But I do not know of the state of affairs there.

like image 147
Basil Bourque Avatar answered Oct 17 '22 07:10

Basil Bourque


You need an update from https://download.eclipse.org/releases/2021-03/ . Support for Apache Tomcat 10 and Jakarta EE JSPs is extremely new.

I suppose you could also just use Tomcat 9.

like image 41
nitind Avatar answered Oct 17 '22 09:10

nitind