title: Unable to instantiate a servlet, getting class not found exception
body: <p>I have created a sample maven project using the following command:</p>
  
  <p>mvn archetype:generate -DgroupId=com.rohit -DartifactId=RohitLoginApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false</p>
  
  <p>Below is the image link of the project structure in eclipse:</p>
  
  <p><a href="https://i.stack.imgur.com/hD1hs.png" rel="nofollow noreferrer">Maven project structure in eclipse</a></p>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.rohit&lt;/groupId&gt;
    &lt;artifactId&gt;RohitLoginApp&lt;/artifactId&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;RohitLoginApp Maven Webapp&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
        &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
        &lt;version&gt;3.0.1&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;3.8.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;   
    &lt;/dependencies&gt;
    &lt;build&gt;
      &lt;finalName&gt;RohitLoginApp&lt;/finalName&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>web.xml:</strong></p>
  
  <pre><code>&lt;!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;
  
  &lt;web-app&gt;
    &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;RohitTestServlet&lt;/servlet-name&gt;
      &lt;display-name&gt;RohitTestServlet&lt;/display-name&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;servlet-class&gt;com.company.rohit.RohitTestServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;RohitTestServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/RohitTestServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>RohitTestServlet.java</strong></p>
  
  <pre><code>package com.company.rohit;
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class RohitTestServlet
   */
  public class RohitTestServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public RohitTestServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          String userId = request.getParametker("userName");
          String pwd = request.getParametker("psw");
          response.getWriter().write("User ID and password are received");
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
  }
  </code></pre>
  
  <p><strong>Index.jsp</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;h2&gt;Login Page&lt;/h2&gt;
  &lt;form action="RohitTestServlet"&gt;
    User Name&lt;br&gt;
    &lt;input type="text" name="userName"&gt;
    &lt;br&gt;
    Password&lt;br&gt;
    &lt;input type="password" name="psw"&gt;
    &lt;br&gt;&lt;br&gt;
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I deploy this app on tomcat, it first loads the welcome screen where I enter the userID and password and click on submit button. Then it redirects to servlet url i.e. <a href="http://localhost:8080/RohitLoginApp/RohitTestServlet?userName=" rel="nofollow noreferrer">http://localhost:8080/RohitLoginApp/RohitTestServlet?userName=</a>"xyz"&amp;psw="www". However its unable to hit the servlet and get the response. Below is the error:</p>
  
  <p><strong>SEVERE: Allocate exception for servlet RohitTestServlet
  java.lang.ClassNotFoundException: com.company.rohit.RohitTestServlet
      at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1856)
      at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1705)
      at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
      at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
      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:169)
      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:318)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)</strong></p>
  
  <p>It is unable to load the class. I had done clean build lot of times but still its unable to load the servlet.</p>