title: HTTP Status 500 - Error instantiating servlet class LoginServlet
body: <p>I am getting the following error.</p>
  
  <pre><code>    type Exception report
  
      message Error instantiating servlet class LoginServlet
  
      description The server encountered an internal error that prevented it from fulfilling this request.
  
      exception
  
      javax.servlet.ServletException: Error instantiating servlet class LoginServlet
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  
      root cause
  
      java.lang.ClassNotFoundException: LoginServlet
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  
      note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs.
  </code></pre>
  
  <p>I am using annotation instead of web.xml file. Since all answers are provided for projects with web.xml file. I find difficult to locate answer for my problem. Given below are my login.jsp page and LoginServlet class codes.</p>
  
  <p>login.jsp</p>
  
  <pre><code>    &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html lang="en"&gt;
      &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;APIS&lt;/title&gt;
      &lt;link rel="stylesheet" href="public/css/bootstrap.min.css"&gt;
      &lt;link rel="stylesheet" href="public/css/style.css"&gt;
      &lt;%@page import= "com.servlet.LoginServlet" %&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;ul class="nav navbar-nav"&gt;
                  &lt;li&gt;&lt;a href="index.jsp"&gt;&lt;span class="glyphicon glyphicon-home"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li  class="active"&gt;&lt;a href="login.jsp"&gt;&lt;span class="glyphicon glyphicon-lock"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Login&lt;/a&gt;&lt;/li&gt;
                  &lt;%
  
                                          if (session.getAttribute("agencyname") != null) {
  
                                              if (session.getAttribute("agencyname").toString().equals("slc")) {
                                      %&gt;
                                  &lt;li&gt;&lt;a href="register.jsp"&gt;&lt;span class="glyphicon glyphicon-user"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;New Register&lt;/a&gt;&lt;/li&gt;
  
                                  &lt;%
                                      }
  
  
                                  %&gt;
                                  &lt;li&gt;&lt;a href="resetPassword.jsp"&gt;&lt;span class="glyphicon glyphicon-refresh"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Reset Password&lt;/a&gt;&lt;/li&gt;
                                  &lt;%
                                          }
  
                                  %&gt;
  
                &lt;/ul&gt;
  
  
                &lt;form class="login-form" action="LoginServlet" method="post"&gt;
                &lt;h2 class="form-signin-heading" style="margin-left:20px;margin-bottom:30px;"&gt;Sign In&lt;/h2&gt;
                &lt;div class="form-group"&gt;
                    &lt;input type="text" class="form-control" id="exampleInputEmail1" placeholder="UserName" name="UserName"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                    &lt;input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="Password"&gt;
                &lt;/div&gt;
                &lt;input type="submit" class="btn btn-success btn-block" value="Submit"&gt;
           &lt;/form&gt;
  
      &lt;/body&gt;
  
      &lt;script src="public/js/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="public/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>LoginServlet class</p>
  
  <pre><code>    package com.servlet;
  
      import com.controller.UserDAO;
      import com.model.OgaUser;
      import java.io.IOException;
      import java.io.PrintWriter;
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.servlet.http.HttpSession;
  
  
      @WebServlet(name = "LoginServlet", urlPatterns = {"/LoginServlet"})
      public class LoginServlet extends HttpServlet {
  
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      try (PrintWriter out = response.getWriter()) {
          /* TODO output your page here. You may use following sample code. */
          out.println("&lt;!DOCTYPE html&gt;");
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet LoginServlet&lt;/title&gt;");
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;h1&gt;Servlet LoginServlet at " + request.getContextPath() + "&lt;/h1&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
      }
  }
  
  // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
  
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  
  
  }
  
  
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  
      System.out.println("******************************");
      System.out.println("In doPost method");
  
      String username = request.getParameter("UserName");
      String password = request.getParameter("Password");
      //OgaUser ou = new OgaUser();
  
      String loginResult = UserDAO.login(username, password);
      if (loginResult != null) {
  
          HttpSession session = request.getSession();
          if (loginResult.equalsIgnoreCase("slc")) {
              session.setAttribute("agency", "slc");
              session.setAttribute("username","Harsha");
              response.sendRedirect("index.jsp");
          } else {
              response.sendRedirect("index.jsp");
          }
      } else {
  
      }
  
  }
  
  
      @Override
      public String getServletInfo() {
      return "Short description";
      }// &lt;/editor-fold&gt;
  
      }
  </code></pre>