If you run with crosscontext enabled: <% javax.servlet.ServletContext context = pageContext.getServletContext().getContext("/jsp-examples/cal/"); if (null!= context) { out.print(context.getRealPath("/")); } %> Fine, result is: D:\java\jakarta-tomcat-5.0.19\webapps\jsp-examples\ If you call getContext("/anothercontext"); it still works if /anothercontext is included with a context.xml file in D:\java\jakarta-tomcat-5.0.19\conf\Catalina\localhost But getContext("/anothercontext/") i.e. the slash or any existing path appended results in D:\java\jakarta-tomcat-5.0.19\webapps\ROOT\ It seems the context-lookup algorithm checks only the part specified with <Context path="/anothercontext" in the xml file. But getContext() should find a context, regardless how the context is made known to the container.
Obviously not.
I get C:\java\jakarta-tomcat-5.0.19\webapps\ROOT\ C:\java\jakarta-tomcat-5.0.19\webapps\ROOT\ C:\java\jakarta-tomcat-5.0.19\webapps\..\server\webapps\manager\ for <% javax.servlet.ServletContext context; context = pageContext.getServletContext().getContext("/manager/"); if (null!= context) { out.print(context.getRealPath("/")); } out.print("<p>"); context = pageContext.getServletContext().getContext("/manager/manager-howto.html"); if (null!= context) { out.print(context.getRealPath("/")); } out.print("<p>"); context = pageContext.getServletContext().getContext("/manager"); if (null!= context) { out.print(context.getRealPath("/")); } %> Note that the scriptlet must be run from a context with crossContext="true". The output should be three times the third output line, corresponding to http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/javax/servlet/ServletContext.html#getContext(java.lang.String)
I did test it. Thanks for not wasting my time.
For those that also run into this bug, it was fixed after the release of jakarta-tomcat-5.0.19. In ApplicationContextFacade.java there was while (true) { child = (Context) host.findChild(mapuri); if (context != null) break; int slash = mapuri.lastIndexOf('/'); if (slash < 0) break; mapuri = mapuri.substring(0, slash); } The if (context != null) was always true, it is now if (child != null).