Hello everyone,
Can you help me with the following problem.
I am working on Eclipse IDE. I created new Dynamic Web Project and when I tried to create a Servlet class though every required package is imported it gives a compiler error.
The following is a sample code.

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

The errors are on the last three import statements.
Please give me your answer.

The errors are on the last three import statements.

What error messages exactly?

It does not recognize the javax.servlet package.

The error message is the import javax.servlet cannot be resolved

Sounds like you are missing stuff that is available only with Java EE. Did you installed any Java EE?

Thank you everyone, I got the solution. one of the following is the solution.

configure Tomcat to your Eclipse IDE before you create the web project
OR
If you created the Web Project before Tomcat is configured do the following procedures:
Right-click on your project -> Build Path -> Configure Build Path ->
Click on Libraries tab -> Click Add External JARs button ->
select servlet-api.jar file from you Tomcat-lib folder -> click OK.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.