title: Error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver even though I've installed the mysql conncetor
body: <p>I'm getting an error when I try to log on at localhost:8080 with my code. Can someone please help me. I'm new to web application development. I've connected to a database (mysql) which contains <code>employee_id</code> and <code>password</code> columns which the JAVA application will check with to validate the login. But it is returning an error. I have attached all my files below as well as the error, thanks! I'm getting the error</p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver</p>
  </blockquote>
  
  <p>even though I've installed the connector. </p>
  
  <p>Login.java (servlet)</p>
  
  <pre><code>import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  
  public class Login extends HttpServlet {
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
  
      String employee_id = request.getParameter("employee_id");
      String password = request.getParameter("password");
      if(Validate.checkUser(employee_id, password)) { 
          RequestDispatcher rs = request.getRequestDispatcher("Welcome");
          rs.forward(request, response);
      }
      else
      {
         out.println("Employee ID or Password is incorrect. Please try again.");
         RequestDispatcher rs = request.getRequestDispatcher("index.html");
         rs.include(request, response);
      }
  }  
  
  
      }
  </code></pre>
  
  <p>Welcome.java (servlet)</p>
  
  <pre><code>import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  
  public class Welcome extends HttpServlet {
  protected void doPost(HttpServletRequest request, HttpServletResponse     response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      out.println("Welcome user");
    }  
  }
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Login Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="login" method="post"&gt;
  &lt;h3&gt;
  Employee Login
  &lt;/h3&gt;
  &lt;b&gt;Employee ID:&lt;/b&gt; &lt;br&gt;
  &lt;input type="text"name="employee_id" size="20"&gt;&lt;br&gt;&lt;br&gt;
  &lt;b&gt;Password:&lt;/b&gt;&lt;br&gt;
  &lt;input type="password" name="password" size="20"&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit" value="Login"&gt;&lt;br&gt;&lt;br&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Validate.java (class)</p>
  
  <pre><code>import java.sql.*;
  public class Validate
  {
  public static boolean checkUser(String employee_id, String password)
  {
      boolean st = false;
      try { 
          Class.forName("com.mysql.jdbc.Driver"); 
  
          Connection con =      DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll", "root", ""); 
          PreparedStatement ps = con.prepareStatement("select * from employee_login where employee_id =? and password = ?");
          ps.setString(1, employee_id);
          ps.setString(2, password);
          ResultSet rs =ps.executeQuery();
           st = rs.next();
  
       }catch(Exception e)
        {
            e.printStackTrace();
        }
           return st;                 
    }   
  }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" &gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;login&lt;/servlet-name&gt;
      &lt;servlet-class&gt;Login&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;Welcome&lt;/servlet-name&gt;
      &lt;servlet-class&gt;Welcome&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;login&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Welcome&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/Welcome&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>AND I"M GETTING THIS ERROR WHEN I TRY TO LOG IN:</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1854)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1703)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:264)
  at Validate.checkUser(Validate.java:8)
  at Login.doPost(Login.java:15)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:745) 
  </code></pre>