'package javax.servlet.annotation does not exist

I have some of the following imports defined like the following as shown in the image below.

enter image description here

I am wondering, how can I eliminate "package javax.servlet.annotation does not exist" error. I am currently working on "Java Web" type of project in Netbeans 7.4. .

Secondly, I believe , the above error is the reason behind my second error related to "WebServlet" which is shown in the image above (line #44).

Please let me know how to fix this problem.

Read some other posts like this one, but I believe they are not using Netbeans and not sure if I should update tomcat as mentioned in the post. The location of the servlet api jar file is as shown in the image below:

enter image description here



Solution 1:[1]

Solution: Add Java EE Web API Library.

  1. In the project window, right-click <libraries>. Then click <Add Library>. then choose <Java EE Web API Library>

Solution 2:[2]

If you are using tomcat 10 change the import statement from :`javax.servlet.----- to import jakarta.servlet.------.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pang
Solution 2 ahmed