You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Richard Evans <rd...@webtrak.co.uk> on 2000/11/11 19:19:50 UTC

Contexts and dispatchers

If I call ServletContext.getContext(uri) to find the web-app which handles a
particular URI, how do I then use getRequestDispatcher to forward the
request to the APP?

The uri given to getContext is absolute, relative to the server root, yet
getRequestDispatcher() requires a path relative to the root of the context.
This means that I have to strip off the context root from the uri, but I can
fin't a method which returns this root.

Example:

I have web apps with roots "/app1" and "/app2".  A servlet in app1 computes,
via properties and internal aliasing, a new uri "/app2/file/x/y".  I can
call getContext to find the ServletContext for "/app2":

	String uri = "/app2/file/x/y";
	ServletContext ctxt =
getServletConfig().getServletContext().getContext(uri);

But now want to call ctxt.getRequestDispatcher() and I have to give it
"/file/x/y".  (The URL without the context root).  How to I find the context
root?

Richard