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:
- In Eclipse, select "File" -> "New" -> "Project" from the menu bar.
- 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".
- In the "New Web Project" window, enter a name for your project and click "Finish".
- Right-click on your project in the "Project Explorer" and select "Properties" from the context menu.
- In the "Properties" window, select "Java Build Path" from the list on the left and then click on the "Libraries" tab.
- Click on the "Add External JARs" button.
- 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.
- Select the servlet-api.jar file and click "Open".
- 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.