rocky
rocky

Reputation: 435

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

Upvotes: 9

Views: 28760

Answers (3)

ahmed
ahmed

Reputation: 31

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

Upvotes: 1

ucheN
ucheN

Reputation: 181

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>

Upvotes: 14

Braj
Braj

Reputation: 46841

WebServlet is added in servlet-api version 3.0, so make sure you are using updated version and it's added in the class path of the project.

Have a look at servlet-api-2.5 classes where WebServlet.class is not included, it's part of servlet-api-3.x classes

Upvotes: 5

Related Questions