I am trying to include a JSP page after the end of a filter. I have the following code:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException, IOException {
try {
chain.doFilter(request, response);
}
finally {
HttpServletRequest httpRequest = (HttpServletRequest) request;
RequestDispatcher dispatcher = httpRequest.getRequestDispatcher("/WEB-INF/logging/logAppender.jsp");
dispatcher.include(request, response); // This does not work!
dispatcher.include(request, response); // The second time it works?
}
}
Pretty simple Filter I think. However, as you can see above, for some reason calling include the first time doesn’t do anything. I am just confused and tired of debugging. I have tried calling .flushBuffer(), getWriter().flush(), all kinds of close() and still don’t understand. Any ideas would be helpful?
There are too many unknowns and a lot of things that can only be figured out through debugging for me to give any kind of answer. A good resource that may help you is Marty Hall’s Moreservlets book. You can read it for free at http://pdf.moreservlets.com/. Read chapter 9 on Filters.