On 31/12/2015 07:40, Tomasz Macnar wrote: > Hi, > > I have problem with get ROOT servlet context from other application (on > the same server) in tomcat 8.0.30. > My code look this: > > public class TestServlet extends HttpServlet { > > @Override > public void init() throws ServletException { > > ServletContext servletContext = getServletContext(); > > System.out.println("Servlet START: " + > servletContext.getContextPath()); > > String[] contextTab = { "/", "/app1", "/app2" }; > > for (String con : contextTab) { > System.out.println("Context " + con + " : " + > servletContext.getContext(con)); > } > } > } > > This servlet I have in app1 and app2 with > <load-on-startup>1<load-on-startup>. > > And in context "/" always I have null. In server.xml i have configuration: > > <Context path="" docBase="${catalina.base}/webapps/ROOT" > crossContext="true" /> > <Context path="/app1" docBase="${catalina.base}/webapps/app1" > crossContext="true" /> > <Context path="/app2" docBase="${catalina.base}/webapps/app2" > crossContext="true" /> > > And the output is: > Servlet START: /app1 > Context / : null > Context /app1 : null > Context /app2 : null > > Servlet START: /app2 > Context / : null > Context /app1 : org.apache.catalina.core.ApplicationContextFacade@8c6fb37 > Context /app2 : null > > > I debug source of tomcat and find, that ROOT context (with empty "path" > in configuration server.xml) is added to ContainerBase class (HashMap > name children) in key "", but I suppose it should add ROOT context with > key "/".
No. > Please tell me if i have wrong configuration or other thing ? The results above are giving you a big hint. app1 can't see any other apps, but app2 can see app1 yet they are using exactly the same code. Think about the order in which applications start and when the above code runs. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org