title: Java - Servlet 404 error
body: <p>I am a newbie in servlet programming.</p>
  
  <p>The following is my sample servlet code</p>
  
  <p><strong>Sample.Java</strong></p>
  
  <pre><code>public class Sample extends HttpServlet {
      protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
          res.setContentType("text/html");  
          PrintWriter pw=res.getWriter();  
  
          String name=req.getParameter("name");//will return value  
          pw.println("Welcome "+name);  
          pw.close();  
      }
  }
  </code></pre>
  
  <p><strong>Web.xml</strong></p>
  
  <pre><code>&lt;web-app&gt;
  &lt;servlet&gt;
  &lt;servlet-name&gt;sampleservlet&lt;/servlet-name&gt;
  &lt;servlet-class&gt;Sample&lt;/servlet-class&gt;
  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; 
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;sampleservlet&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/Sample&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Index.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="Sample" method="get"&gt;  
  Enter your name&lt;input type="text" name="name"&gt;&lt;br&gt;  
  &lt;input type="submit" value="login"&gt;  
  &lt;/form&gt;  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>My problem</strong></p>
  
  <p>When I right click on my project and then click <code>Run as -&gt; Run on server</code>, I select the server, it asks me for to select a server and then I select the server to run. In the eclipse window a browser window is opened which has the address URL as <a href="http://localhost:8080/Sample/" rel="nofollow noreferrer">http://localhost:8080/Sample/</a></p>
  
  <p><img src="https://i.stack.imgur.com/kHpVx.png" alt="enter image description here"></p>
  
  <p>When I click on <code>login</code> it gives me an error like this,</p>
  
  <p><strong>HTTP Status 404 - /Sample/welcome</strong></p>
  
  <hr>
  
  <p><strong>type</strong> Status report</p>
  
  <p><strong>message</strong> /Sample/welcome</p>
  
  <p><strong>description</strong> The requested resource is not available.</p>
  
  <hr>
  
  <p><strong>Apache Tomcat/7.0.62</strong></p>
  
  <p><strong>Screenshot</strong></p>
  
  <p><img src="https://i.stack.imgur.com/hNEvj.png" alt="enter image description here"></p>
  
  <p>Why am I getting an error like this ?</p>
  
  <p><strong>Other details</strong></p>
  
  <p>Server:apache-tomcat-7.0.62
  IDE: Eclipse Java EE kepler</p>
  
  <p>Steps I tried to solve the problem</p>
  
  <p>I tried these,</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/20871886/getting-http-status-404-error-when-trying-to-run-servlet">Getting HTTP Status 404 error when trying to run servlet</a></li>
  </ol>
  
  <p><strong>Result</strong></p>
  
  <p>I did not see the <code>.class</code> files in <code>WEB-INF</code> folder.</p>
  
  <ol start="2">
  <li><a href="https://stackoverflow.com/questions/19173430/tomcat-giving-404-error-with-servlets">Tomcat giving 404 error with servlets</a></li>
  </ol>
  
  <p><strong>Result</strong>
  In this path "tomcat7\work\Catalina\localhost\your app",the <code>work</code> folder was empty.</p>
  
  <p>Please let me know if I need to post any more details.</p>
  
  <p><strong>Directory structure from IDE</strong></p>
  
  <p><img src="https://i.stack.imgur.com/7Y5Gt.png" alt="enter image description here"></p>