I have 2 webapps working in two contexts: c1, c2 (both immediately after the root). I set startupListener in c1 to split the variable and the other in c2 to extract it.
My startuplistener in c1:
public void contextInitialized(ServletContextEvent sce) {
HashMap <String,Object> database ;
ServletContext context = sce.getServletContext().getContext("/c1");
if (context!=null)
{
context.setAttribute("crossContext", true);
context.setAttribute("cache", database);
}
}
In c2 application, it looks like this:
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext().getContext("/c1");
HashMap<String,Object> database = (HashMap) context.getAttribute("cache");
}
The context in startupListener c2 is always zero, I tried '/ c1', 'c1'. What am I missing? (I use tomcat6 if that matters) Thanks
source
share