title: Apache tomcat and servlet (beginner) - 404 error, maybe classes are not found?
body: <p>I'm a beginner in servlets and for a "hello world style" servlet I installed apache tomcat and created the following under it's <code>webapps</code> directory:</p>
  
  <pre><code>servletdir
  |- index.xhtml
  |- WEB-INF
     |- web.xml
     |- classes
        |- mypackage
           |- ServletClass.class
  </code></pre>
  
  <p>Initialized everything so I could access my servlet on localhost:</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;web-app&gt;
  
  &lt;servlet&gt;
  &lt;servlet-name&gt;myservlet&lt;/servlet-name&gt;
  &lt;servlet-class&gt;mypackage.ServletClass&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;myservlet&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/servleturl/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and the index.xhtml contains a form that has <code>action="/servleturl" method="get"</code></p>
  
  <p>In theory, when I start up tomcat, I should be able to access both the servlet and index.xhtml file now through <code>localhost:8080/servletdir/index.xhtml</code> and submitting the form there. Reaching index is no problem, but when I submit the form, I get a 404 error for the servlet, saying that it "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.".</p>
  
  <p>My servlet class should not be the problem, it extends <code>HttpServlet</code> and overrides <code>doGet</code> to output a simple html via the <code>ServletResponse</code> parameter's <code>getWriter().println()</code>. Can an error in the servlet class cause a 404? Is my directory structure or web.xml wrong?</p>
  
  <p>I have tried multiple directory structures and solutions, including:</p>
  
  <ul>
  <li>flat dir structure in WEB-INF and class not being in package (no "classes" directory)  </li>
  <li>no WEB-INF, everything in servlet dir directly  </li>
  <li>wrap WEB-INF and index.xhtml in a directory named "WebContent"  </li>
  <li>keep "classes" directory but use no package, put class files directly into classes*</li>
  </ul>
  
  <p>I have followed multiple resources including some tutorials and many questions here which are not directly related to my problem, but contain some info, but as I'm a complete newbie to this technology I can't deduce which resource is good and which isn't, that't why I tried almost everything I found.</p>
  
  <p>The directory structure described at the top is directly on the disk as this structure, not in a war file, but as I can access some parts, I guess this isn't the problem.</p>
  
  <p>*: note that I recompiled the java files with the according "package" at the file's top line every time the directory structure representing the package changed, that's not the problem</p>