title: Tomcat ClassNotFoundException for HttpServlet
body: <p>We are getting a <code>java.lang.ClassNotFoundException: HttpServlet</code> with a JSP project running on the Apache Tomcat server (v5.5) in Eclipse. The lib folder under Web-inf does have the servelt-api jar. And furthermore we have imported the javax.servlet.http.* library. But still we are getting this exception. </p>
  
  <pre><code>package com.bean;
  
  import java.io.*;
  import java.util.*;
  import java.sql.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  public class AdminLogin extends HttpServlet{
      ArrayList list=new ArrayList();
  
      public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{     
  
          try{
          response.setContentType("text/html");       
          PrintWriter out=response.getWriter();    
          String id=request.getParameter("user");
          String pass=request.getParameter("pass");
          System.out.println("ID==================&gt;&gt;"+id+"PASS========&gt;&gt;"+pass);
          if(id.equalsIgnoreCase("admin")&amp;&amp;pass.equalsIgnoreCase("admin"))
                  {
                      response.sendRedirect("AdminPage.jsp");                 
                  }
                  else
                  {
                      response.sendRedirect("Failure.html");        
                  }           
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
          }
  }
  </code></pre>
  
  <p>Error Stack Trace:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: HttpServlet
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClassCond(Unknown Source)
      java.lang.ClassLoader.defineClass(Unknown Source)
      java.security.SecureClassLoader.defineClass(Unknown Source)
      org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847)
      org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:873)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1326)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
      org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
      org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
      org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
      org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
      java.lang.Thread.run(Unknown Source)
  root cause
  
  java.lang.ClassNotFoundException: HttpServlet
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClassCond(Unknown Source)
      java.lang.ClassLoader.defineClass(Unknown Source)
      java.security.SecureClassLoader.defineClass(Unknown Source)
      org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847)
      org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:873)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1326)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
      org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
      org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
      org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
      org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
      java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
      &lt;display-name&gt;CarPooling&lt;/display-name&gt;
      &lt;servlet&gt;
          &lt;description&gt;
          &lt;/description&gt;
          &lt;display-name&gt;AdminLogin&lt;/display-name&gt;
          &lt;servlet-name&gt;AdminLogin&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.bean.AdminLogin&lt;/servlet-class&gt;
          &lt;/servlet&gt;
          &lt;servlet&gt;
   &lt;servlet-name&gt;employee&lt;/servlet-name&gt;
   &lt;servlet-class&gt;com.bean.UserLogin&lt;/servlet-class&gt;
   &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;AdminLogin&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/demo&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;  
    &lt;servlet-mapping&gt;   
    &lt;servlet-name&gt;employee&lt;/servlet-name&gt;
   &lt;url-pattern&gt;/login&lt;/url-pattern&gt;                             
   &lt;/servlet-mapping&gt;  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;      
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>project folder structure:
  <img src="https://i.stack.imgur.com/aOJyN.png" alt="enter image description here"></p>