0

The problem is that the servlet can't include response from another one. Well, I have one servlet called "Query" which has such block:

RequestDispatcher dispatcher = request.getRequestDispatcher("/servlets/counter");
    if (dispatcher != null) {
        out.println("<br>Number of visits: ");
        request.setAttribute(Counter.ATTRIBUTE, Query.class.getName());
        dispatcher.include(request, response);
    }
    out.println("</body>");

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:

if (counterName == null) counterName = (String)request.getAttribute(ATTRIBUTE);

So, when I run "Query" there is no output from "Counter". You can review the full project from this repository Thank you in advance!

1 Answers1

0

I figured it out! Mistake was at the .getRequestDispatcher method. The parameter has to contain not servlet's class location, but it's mapping. Thanks to this post

Community
  • 1
  • 1