title: How to redirect html button -> Servlet -> another html page?
body: <p>I have a html page with 2 buttons with the same form action (When the user presses a button, the form redirects it to a servlet and then in that servlet, I want it to redirect to another html page based on the button pressed in the html page). </p>
  
  <p>Html page</p>
  
  <pre><code>&lt;form action ="ManageEmployeeRedirect" method = "post"&gt; 
  &lt;input type="submit" value="Create New Employee Account" name="ID1"&gt; 
  &lt;br&gt;
  &lt;br&gt;
  &lt;input type="submit" value="Update Existing Employee Account" name="ID2"&gt; 
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Servlet</p>
  
  <pre><code>import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  
  public class ManageEmployeeRedirect extends HttpServlet { 
  
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
  
          String name = request.getParameter("ID1");
          String name2 = request.getParameter("ID2"); 
  
          if("ID1".equals(name)){
              RequestDispatcher rs = request.getRequestDispatcher("index.html");
              rs.forward(request, response);
          }
          else if("ID2".equals(name2)){ 
              RequestDispatcher rs = request.getRequestDispatcher("changePassAdmin.html"); 
              rs.forward(request, response);
          }
      }
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
                 processRequest(request, response);
            }
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
                 processRequest(request, response);
      }
  }
  </code></pre>