0

Please guys I am new in servlet i created a project in eclipse and add new servlet in it after that i have a lot of errors in it and can not fix them

and all import lines have a red underline on it and can not fix it Is this a problem in configuration? or what

/**
 * Servlet implementation class ServletTest
 */
@WebServlet(
        description = "first servlet test", 
        urlPatterns = { 
                "/ServletTest", 
                "/ServletTestPath"
        })
public class ServletTest extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ServletTest() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

}
randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72
Hamada Ibrahim
  • 103
  • 1
  • 1
  • 6

2 Answers2

1

Hope you created Dynamic Web project (File -> New -> Other, search for dynamic). Make sure you configured tomcat server in eclipse. After that do the following. Right click on project -> Properties -> Project Factes -> Select "Runtimes" tag -> select a server

Following link help you to configure server in Eclipse.

http://self-learning-java-tutorial.blogspot.in/2014/12/configure-tomcat-server-in-eclipse.html

Hari Krishna
  • 3,658
  • 1
  • 36
  • 57
0

Here have a look at this answer

to a similar question to yours.

servlet-api.jar is required to resolve all the errors you are getting.

Community
  • 1
  • 1
Aniket Paul
  • 233
  • 1
  • 11