0

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.

Edited by pritaeas: Moved.

3
Contributors
5
Replies
20
Views
3 Years
Discussion Span
Last Post by Nesre
0

It does not recognize the javax.servlet package.

0

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

1

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.

Edited by peter_budo: Formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.