title: Servlet chaining - simple example
body: <p>I see a strange issue in a simple servlet chaining example that I am trying:</p>
  
  <p>Servlet 1:</p>
  
  <pre><code>public class gatewayservlet extends HttpServlet {
  
    public void doPost(HttpServletRequest request , 
      HttpServletResponse response)
      throws ServletException , IOException {
          doGet(request,response);
    }
  
    public void doGet(HttpServletRequest request , 
      HttpServletResponse response)
      throws ServletException , IOException {
  
      response.setContentType("text/plain");
  
      PrintWriter out = response.getWriter();
  
      name = request.getParameter("name");
  
      RequestDispatcher rd = getServletConfig().getServletContext().getRequestDispatcher("/justServlets/secondservlet");
  
      if(name!=null) {
        request.setAttribute("UserName",name);
        rd.forward(request , response);
        // Forward the value to another Secondservlet
      } else {
        response.sendError(response.SC_BAD_REQUEST, 
          "UserName Required");
      }
  
    }
  
  }
  </code></pre>
  
  <p>Servlet 2:</p>
  
  <pre><code>public class secondservlet extends HttpServlet {
  
    public void doGet(HttpServletRequest request , 
      HttpServletResponse response)
      throws ServletException , IOException {
  
      response.setContentType("text/plain");
  
      PrintWriter out = response.getWriter();
  
      String UserName = (String)request.getAttribute("UserName");
  
      out.println("The UserName is "+ UserName);
  
    }
  
  
    public void doPost(HttpServletRequest request , 
      HttpServletResponse response)
      throws ServletException , IOException {
          doGet(request,response);
    }
  
  }
  </code></pre>
  
  <p>And the invoking form:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;FORM ACTION="/justServlets/gateway" METHOD=POST&gt;
  &lt;P&gt;Please Fill the Registration Form&lt;/p&gt;&lt;br&gt;
  Enter Your Name&lt;input type="text" name="name"&gt;&lt;br&gt;
  &lt;input type="submit" value="send"&gt;
  &lt;/FORM&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The 'POST' gives a 405(Method not allowed) error.
  However ,invoking the first servlet as ..../justServlets/gateway?name=Socrates works.
  Whats the matter?</p>