title: How to correctly include output from one servlet to another?
body: <p>The problem is that the servlet can't include response from another one. Well, I have one servlet called "Query" which has such block:</p>
  
  <pre><code>RequestDispatcher dispatcher = request.getRequestDispatcher("/servlets/counter");
      if (dispatcher != null) {
          out.println("&lt;br&gt;Number of visits: ");
          request.setAttribute(Counter.ATTRIBUTE, Query.class.getName());
          dispatcher.include(request, response);
      }
      out.println("&lt;/body&gt;");
  </code></pre>
  
  <p>It is designed to include another servlet's response into the current servlet. Then, I have the other servlet called "Counter" which has this line:</p>
  
  <pre><code>if (counterName == null) counterName = (String)request.getAttribute(ATTRIBUTE);
  </code></pre>
  
  <p>So, when I run "Query" there is no output from "Counter". You can review the full project from <a href="https://github.com/ereminmax/MyFirstServlets" rel="nofollow">this repository</a> Thank you in advance!</p>