title: HTTP status 404 error running TimeForm servlet project in NetBeans
body: <p>I'm trying to test the following servlet in a web project created with NetBeans. It constitutes a simple form which allows users to select locale and timezone from a list and display relevant information accordingly.</p>
  
  <p>Here is the servlet code:</p>
  
  <pre><code>public class TimeForm extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";
    private Locale[] allLocale = Locale.getAvailableLocales();
    private String[] allTimeZone = TimeZone.getAvailableIDs();
  
    /** Process the HTTP Get request */
    public void doGet(HttpServletRequest request, HttpServletResponse
        response) throws ServletException, IOException {
      response.setContentType(CONTENT_TYPE);
      PrintWriter out = response.getWriter();
      out.println("&lt;h3&gt;Choose locale and time zone&lt;/h3&gt;");
      out.println("&lt;form method=\"post\" action=" +
        "/localhost:8080/TimeForm&gt;");
      out.println("Locale &lt;select size=\"1\" name=\"locale\"&gt;");
  
      // Fill in all locales
      for (int i = 0; i &lt; allLocale.length; i++) {
        out.println("&lt;option value=\"" + i +"\"&gt;" +
          allLocale[i].getDisplayName() + "&lt;/option&gt;");
      }
      out.println("&lt;/select&gt;");
  
      // Fill in all time zones
      out.println("&lt;p&gt;Time Zone&lt;select size=\"1\" name=\"timezone\"&gt;");
      for (int i = 0; i &lt; allTimeZone.length; i++) {
        out.println("&lt;option value=\"" + allTimeZone[i] +"\"&gt;" +
          allTimeZone[i] + "&lt;/option&gt;");
      }
      out.println("&lt;/select&gt;");
      out.println("&lt;p&gt;&lt;input type=\"submit\" value=\"Submit\" &gt;");
      out.println("&lt;input type=\"reset\" value=\"Reset\"&gt;&lt;/p&gt;");
      out.println("&lt;/form&gt;");
      out.close(); // Close stream
    }
  
    /** Process the HTTP Post request */
    public void doPost(HttpServletRequest request, HttpServletResponse
        response) throws ServletException, IOException {
      response.setContentType(CONTENT_TYPE);
      PrintWriter out = response.getWriter();
      out.println("&lt;html&gt;");
      int localeIndex = Integer.parseInt(
        request.getParameter("locale"));
      String timeZoneID = request.getParameter("timezone");
      out.println("&lt;head&gt;&lt;title&gt;Current Time&lt;/title&gt;&lt;/head&gt;");
      out.println("&lt;body&gt;");
      Calendar calendar =
        new GregorianCalendar(allLocale[localeIndex]);
      TimeZone timeZone = TimeZone.getTimeZone(timeZoneID);
      DateFormat dateFormat = DateFormat.getDateTimeInstance(
        DateFormat.FULL, DateFormat.FULL, allLocale[localeIndex]);
      dateFormat.setTimeZone(timeZone);
      out.println("Current time is " +
        dateFormat.format(calendar.getTime()) + "&lt;/p&gt;");
      out.println("&lt;/body&gt;&lt;/html&gt;");
      out.close(); // Close stream
    }
  }
  </code></pre>
  
  <p>And this is the web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;TimeForm&lt;/servlet-name&gt;
          &lt;servlet-class&gt;hw5.TimeForm&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;TimeForm&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/TimeForm&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>When I run the project through NetBeans, the code seems to compile fine and I get to select the locale and timezone. But when I click Submit, I get the following error:</p>
  
  <p><a href="https://i.stack.imgur.com/avxvE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/avxvE.jpg" alt="enter image description here"></a></p>
  
  <p>Could someone explain to me why this is happening and how to go about fixing it?</p>
  
  <p><a href="https://i.stack.imgur.com/5TjtS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5TjtS.jpg" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/JyLlS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JyLlS.jpg" alt="enter image description here"></a><a href="https://i.stack.imgur.com/O2C0X.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O2C0X.jpg" alt="enter image description here"></a></p>