title: Forward request from servlet to jsp
body: <p>I have a small application (HTML form, servlet as controller and jsp files) and i try to figure out why i cannot to forward the request from servlet to jsp files.</p>
  
  <p>the problem is after submit from html, showed up "HTTP Status 404" </p>
  
  <p>Application flow:</p>
  
  <ol>
  <li>submit from html.</li>
  <li>controller get the name from html.</li>
  <li>controller supposed to move the request to jsp files.</li>
  </ol>
  
  <p>thanks!</p>
  
  <p>project hierarchy:
  <a href="http://s23.postimg.org/kgt7r7lwb/Capture.jpg" rel="noreferrer">http://s23.postimg.org/kgt7r7lwb/Capture.jpg</a></p>
  
  <p>main.html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;title&gt;Coupons categories&lt;/title&gt;
  &lt;body&gt;
    &lt;h1 align="center"&gt;Coupons categories&lt;/h1&gt;
    &lt;form method="GET" action="Controller"&gt;
      Select category 
      Type:
      &lt;select name="type" size=1&gt;
        &lt;option value="restaurants"&gt;Restaurants&lt;/option&gt;
        &lt;option value="electrics"&gt;Electrics&lt;/option&gt;
        &lt;option value="hotels"&gt;Hotels&lt;/option&gt;
      &lt;/select&gt;
      &lt;br&gt;&lt;br&gt;
        &lt;input type="Submit"&gt;
     &lt;/form&gt;
  &lt;/body&gt;
  &lt;html&gt;
  </code></pre>
  
  <p>controller.java:</p>
  
  <pre><code>   @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          //PrintWriter out = response.getWriter();
          //out.write(request.getPathInfo());
  
          String path = request.getParameter("type");
          if(path.equals("electrics"))
          {
              request.setAttribute("timestamp", new Date());
              RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/view/electrics.jsp");
              dispatcher.forward(request, response);
          }
          else if(path.equals("hotels"))
          {
              request.setAttribute("timestamp", new Date());
              RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/view/hotels.jsp");
              dispatcher.forward(request, response);          
          }
          else if(path.equals("restaurants"))
          {
              request.setAttribute("timestamp", new Date());
              RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/view/restaurants.jsp");
              dispatcher.forward(request, response);          
          }
      }
  </code></pre>
  
  <p>electrics.jsp:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=windows-1255"
      pageEncoding="windows-1255"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1255"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h2&gt;products list...&lt;/h2&gt;
      &lt;%
      Object ob = request.getAttribute("timestamp");
      out.println(ob);
      %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre><code>    &lt;description&gt;
        CouponsServer
      &lt;/description&gt;
      &lt;display-name&gt;Controller for CouponsServer&lt;/display-name&gt;
  
      &lt;servlet&gt;
        &lt;servlet-name&gt;Controller&lt;/servlet-name&gt;
        &lt;servlet-class&gt;uses.server.Controller&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Controller&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/Controller&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>update:
  Probably the problem is in the controller.java.
  When i try the following code, i got HTTP Status 500.
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {</p>
  
  <pre><code>        PrintWriter out = response.getWriter();
          out.write(request.getPathInfo());
      }
  </code></pre>