title: Error instantiating servlet class Login
body: <p>i am trying an Log in example with servlets using RequestDispatcher but getting this HTTP Status 404 -
  ,i have hard coded  error the password in the code itself ,but getting some times HTTP Status 500 - Error instantiating servlet class Login
  <img src="https://i.stack.imgur.com/MjNim.jpg" alt="enter image description here">
  <strong>web.xml</strong>
       </p>
  
  <pre><code>&lt;web-app&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;WelcomeServlet&lt;/servlet-name&gt;  
          &lt;servlet-class&gt;WelcomeServlet&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;WelcomeServlet&lt;/servlet-name&gt;  
          &lt;url-pattern&gt;/WelcomeServlet&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-list&gt;  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>index.html</strong> </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="ISO-8859-1"&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;form action="servlet1" method="post"&gt;  
      Name:&lt;input type="text" name="userName"/&gt;&lt;br/&gt;  
      Password:&lt;input type="password" name="userPass"/&gt;&lt;br/&gt;  
      &lt;input type="submit" value="login"/&gt;  
      &lt;/form&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>Login.java</strong> </p>
  
  <pre><code> package com.emma.saurabh;
  
      import java.io.IOException;
      import java.io.PrintWriter;
  
      import javax.servlet.*;
      import javax.servlet.http.*;
  
  
      public class Login extends HttpServlet {
  
          /**
           * 
           */
          private static final long serialVersionUID = 1L;
  
          public void doGet(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
  
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();
  
              String p=request.getParameter("userPass");
              if(p.equals("saurabh")){
                  RequestDispatcher rd=request.getRequestDispatcher("servlet2");
                  rd.forward(request, response);
  
              }
              else{
                  out.print("Sorry username or password error!");
                  RequestDispatcher rd=request.getRequestDispatcher("/index.html");
                  rd.include(request, response);
              }
  
          }
  
      }
  
  
  **WelcomeServlet.java**
  
  
      package com.emma.saurabh;
  
          import java.io.*;  
          import javax.servlet.*;  
          import javax.servlet.http.*;  
  
          public class WelcomeServlet extends HttpServlet {  
  
              /**
               * 
               */
              private static final long serialVersionUID = 1L;
  
              public void doPost(HttpServletRequest request, HttpServletResponse response)  
                  throws ServletException, IOException {  
  
              response.setContentType("text/html");  
              PrintWriter out = response.getWriter();  
  
              String n=request.getParameter("userName");  
              out.print("Welcome "+n);  
              }  
  
          }  
  </code></pre>