title: How do I run multiple servlet after single submit button click?
body: <p>I want to run two  servlet when I click  submit button in html page
  Here is  servlet and  html code</p>
  
  <pre><code>package com.serv;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class MyServlet
   */
  @WebServlet("/MyServlet")
  public class MyServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          try {
              String user=request.getParameter("user");
              out.println("&lt;h2&gt;"+user+"&lt;/h2&gt;");
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          }
  
  }
  </code></pre>
  
  <p>here is 2nd  servlet</p>
  
  <pre><code>package com.serv;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class MyServlet2
   */
  @WebServlet("/MyServlet2")
  public class MyServlet2 extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      response.setContentType("text/html");
      PrintWriter out1=response.getWriter();
      try {
          String user1=request.getParameter("user1");
          out1.println("&lt;h2&gt;"+user1+"&lt;/h2&gt;");
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  
  }
  </code></pre>
  
  <p>Here is HTML file</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="post" action="MyServlet"&gt;
          Name&lt;input type="text" name="user"&gt;
  
      &lt;/form&gt;
      &lt;form method="post" action="MyServlet2"&gt;
          Sir Name&lt;input type="text" name="user1"&gt;
      &lt;input type="submit" value="submit"&gt;
      &lt;/form&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I tried placing submit button at different places but its not working . Can some tell me how shall i write the code so both  servlet will be called</p>