问题是servlet不能包含来自另一个的响应。好吧,我有一个名为" Query"有这样的块:
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>");
它被设计为包含另一个servlet对当前servlet的响应。然后,我有另一个名为&#34; Counter&#34;有这条线:
if (counterName == null) counterName = (String)request.getAttribute(ATTRIBUTE);
所以,当我运行&#34;查询&#34;没有来自&#34; Counter&#34;的输出。您可以查看this repository的完整项目,先谢谢您!