title: HTTP Status 404 - Not Found - Servlet and JSP
body: <p>I'm working on one web app. I have problem when I want to test my <code>servlet</code>.
  When I run my servlet error pops up -</p>
  
  <blockquote>
    <p>HTTP Status 404 - Not Found.</p>
  </blockquote>
  
  <p>I search another similar problems but i can't find solution. I think that there is no connection between my servlet and <code>jsp</code> file. Below my code:</p>
  
  <p><strong>GetServletController</strong></p>
  
  <pre><code>    /*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package Servlets;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Enumeration;
  import java.util.List;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   *
   * @author Adam
   */
  public class GetServletController extends HttpServlet {
  
  //    private HandsDBUtil handsDBUtil;
  //
  //    private ServletConfig config = getServletConfig();
  //    private ServletContext context = config.getServletContext();
  //
  //    private String user = null;
  //    private String pass = null;
  //    private String c_name = null;
  //    private String url = null;
  //    @Override
  //    public void init() throws ServletException {
  //        super.init();
  //        Enumeration enumeration = context.getInitParameterNames();
  //        while (enumeration.hasMoreElements()) {
  //            String name = (String) enumeration.nextElement();
  //            switch (name) {
  //                case "url":
  //                    url = context.getInitParameter(name);
  //                    break;
  //                case "pass":
  //                    pass = context.getInitParameter(name);
  //                    break;
  //                case "user":
  //                    user = context.getInitParameter(name);
  //                    break;
  //                case "c_name":
  //                    c_name = context.getInitParameter(name);
  //                    break;
  //            }
  //        }
  //
  //        handsDBUtil = new HandsDBUtil(user, pass, c_name, url);
  //
  //    }
      /**
       * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
       * methods.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
  
          response.setContentType("text/plain; charset=ISO-8859-2");
  
          PrintWriter out = response.getWriter();
  
          out.println("WOW");
  
          HandsDBUtil handsDBUtil;
  
          ServletConfig config = getServletConfig();
          ServletContext context = config.getServletContext();
  
          String user = null;
          String pass = null;
          String c_name = null;
          String url = null;
  
          Enumeration enumeration = context.getInitParameterNames();
          while (enumeration.hasMoreElements()) {
              String name = (String) enumeration.nextElement();
              switch (name) {
                  case "url":
                      url = context.getInitParameter(name);
                      break;
                  case "pass":
                      pass = context.getInitParameter(name);
                      break;
                  case "user":
                      user = context.getInitParameter(name);
                      break;
                  case "c_name":
                      c_name = context.getInitParameter(name);
                      break;
              }
          }
  
          handsDBUtil = new HandsDBUtil(user, pass, c_name, url);
  
          out.println("wow");
          out.println(user);
          try {
              //listHands(request, response);
              List&lt;Hand&gt; hands = handsDBUtil.getHands();
              System.out.println(hands);
              request.setAttribute("HAND_LIST", hands);
  
              RequestDispatcher dispatcher = request.getRequestDispatcher("getHands");
              dispatcher.forward(request, response);
          } catch (Exception ex) {
              throw new ServletException(ex);
          }
      }
  
  //    private void listHands(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, Exception {
  //
  //        List&lt;Hand&gt; hands = handsDBUtil.getHands();
  //
  //        request.setAttribute("HAND_LIST", hands);
  //
  //        RequestDispatcher dispatcher = request.getRequestDispatcher("getHands");
  //        dispatcher.forward(request, response);
  //
  //    }
      // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return "Short description";
      }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  
  <p><strong>jsp</strong></p>
  
  <pre><code>&lt;%@page import="java.util.*, Servlets.GetServletController, Servlets.Hand" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Poker Hands List&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;form action="GetServletController"/&gt;
  
      &lt;%
  
  
          List&lt;Hand&gt; theHands = (List&lt;Hand&gt;) request.getAttribute("HAND_LIST");
          %&gt;
  
      &lt;body&gt;
  
          &lt;%= theHands %&gt;
  
          &lt;div id="wrapper"&gt;
              &lt;div id="header"&gt;
                  &lt;h2&gt;
                      Poker Hands List
                  &lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div id="container"&gt;
              &lt;div id="content"&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;url&lt;/param-name&gt;
          &lt;param-value&gt;jdbc:derby://localhost:1527/lab&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;c_name&lt;/param-name&gt;
          &lt;param-value&gt;org.apache.derby.jdbc.ClientDriver&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;user&lt;/param-name&gt;
          &lt;param-value&gt;lab&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;pass&lt;/param-name&gt;
          &lt;param-value&gt;lab&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;ServletTest&lt;/servlet-name&gt;
          &lt;servlet-class&gt;Servlets.ServletTest&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;GetServletController&lt;/servlet-name&gt;
          &lt;servlet-class&gt;Servlets.GetServletController&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;ServletTest&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/ServletTest&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;GetServletController&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/GetServletController&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;getHands.jsp&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
          &lt;welcome-file&gt;mainMenu.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>