user2039136
user2039136

Reputation: 55

Error in eclipse, servlets

Here's some error im getting on Eclipse

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class HelloServlet extends HttpServlet 

It says HttpServlet cannot be resolved to a type , pls help

Upvotes: 2

Views: 12690

Answers (3)

Joby Wilson Mathews
Joby Wilson Mathews

Reputation: 11116

If your project is maven then add following dependancy :

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

Reference

For gradle projects:

dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}

or download javax.servlet.jar and add to your project.

Steps:

  1. Right click on project.
  2. Go To Properties.
  3. Go to Java Build Path.
  4. Select Add Library option from tabs.
  5. Add Jar Files give path of your servlet-api.jar file.
  6. Clean and build your project.

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94429

You need to add the runtime libraries from your application server.

For example:

Go to project properties. Click Build Path, then the libraries tab. Click add library, then select Server Runtime. Select your server and click OK.

enter image description here

Upvotes: 6

D.S
D.S

Reputation: 1150

check project build path whether Servlets api jar file is included or not. you can add it in two ways:

1) add servlets api .jar file to build path
or
2) add server runtime (i add Tomcat server runtime library) in build path

Hope this helps.

Upvotes: 2

Related Questions