You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Colin Wilson-Salt <co...@london.virgin.net> on 2001/09/24 14:22:43 UTC

Is it legal to forward() to a different context?

Am I allowed to include and forward between servlet contexts?

i.e. Am I allowed to write a method like this:

private void include(ServletRequest request, ServletResponse response, 
                     String contextPath, String relativePath)
throws ServletException, IOException
{
    ServletContext context = getServletContext().getContext(contextPath);
    RequestDispatcher requestDispatcher =
        context.getRequestDispatcher(relativePath);
    requestDispatcher.include(request, response);
}

Because it kind of works. Though if I don't flush() first, things get kind
of screwed up.

If I am allowed to do this, what should I expect to get if I do stuff like
getServletContext() in the included servlet? It seems that I get the context
of the original servlet, not the included one. Which isn't very useful to
me.

Cheers.