How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?

To import the javax.servlet or jakarta.servlet API in an Eclipse project, follow these steps:

  1. In Eclipse, select "File" -> "New" -> "Project" from the menu bar.
  2. In the "New Project" window, select "Java Web" from the list of project types and then select "Web Project" from the list of projects. Click "Next".
  3. In the "New Web Project" window, enter a name for your project and click "Finish".
  4. Right-click on your project in the "Project Explorer" and select "Properties" from the context menu.
  5. In the "Properties" window, select "Java Build Path" from the list on the left and then click on the "Libraries" tab.
  6. Click on the "Add External JARs" button.
  7. In the "JAR Selection" window, navigate to the location of the servlet-api.jar file. This file is usually located in the "lib" folder of your Tomcat installation directory.
  8. Select the servlet-api.jar file and click "Open".
  9. Click "OK" to close the "Properties" window.

You should now be able to import classes from the javax.servlet or jakarta.servlet package in your project.

Note: If you are using a version of Eclipse that is newer than 2018-12, you may need to use the jakarta.servlet API instead of the javax.servlet API, as the Java EE specification has been transferred to the Eclipse Foundation and the package names have been changed to use the "jakarta" namespace.