For an Ant project:
Make sure, you have servlet-api.jar in the lib folder.
For a Maven project:
Make sure, you have the dependency added in POM.xml.
javax.servlet
javax.servlet-api
3.1.0
provided
Another way to do it is: Update the project facets to pick up the right server.
Check this box in this location:
Project → Properties → Target Runtimes → Apache Tomcat (any server)