Hi all, I would like to know how to append (or prepend) some content in a Servlet, after RequestDispatcher#forward is called.
Example code: class MyServlet extends HttpServlet { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String finalUri = ... // compute some resource URI; RequestDispatcher resource = request.getRequestDispatcher(finalUri); response.getWriter().append("prepend string"); resource.forward(request, response); } } I know Javadoc says 'Uncommitted output in the response buffer is automatically cleared before the forward.' so obviously my code does not work properly. I also tried using RequestDispatcher#include but I need to keep response headers, added during the forward/inclusion. So: 1) Is there any way to append content after/before forward? 2) Is there any way to keep response headers added during resource inclusion? 3) Other ideas..? Ty in advance Nicolò Boschi