2

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

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
user2039136
  • 55
  • 1
  • 1
  • 10

3 Answers3

5

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

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • can you please tell me why you do this? What is the logic behind this, as I have set the classpath in enviroment variables for servlet-api.jar and jsp-api.jar why it not works? – kamil Apr 02 '13 at 17:56
2

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.

D.S
  • 1,110
  • 3
  • 11
  • 26
0

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.
Joby Wilson Mathews
  • 10,528
  • 6
  • 54
  • 53