title: How to get the action from the HttpServlet request to dispatch to multiple pages
body: <p>I am using the Page Controller pattern. How could I use the same controller for two different pages by detecting the request action and then dispatching according to the result?</p>
  
  <p>Here is my code:</p>
  
  <p><strong>account.jsp</strong></p>
  
  <pre><code>&lt;form name="input" action="&lt;%=request.getContextPath() %&gt;/edit" method="get"&gt;
     &lt;input type="submit" value="Modifier" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Account Servlet</strong></p>
  
  <pre><code>public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          System.out.println("received HTTP GET");
  
          String action = request.getParameter("action");
  
          if (action == null)
          {
              // the account page
              dispatch(request, response, "/account");    
          }
          else if (action == "/edit") {
              // the popup edit page
              dispatch(request, response, "/edit");
          }
  
          protected void dispatch(HttpServletRequest request,
              HttpServletResponse response, String page)
              throws javax.servlet.ServletException, java.io.IOException {
          RequestDispatcher dispatcher = getServletContext()
              .getRequestDispatcher(page);
          dispatcher.forward(request, response);
  }
      }
  </code></pre>