Tomcat could not get ServletContext of another webapp

I am using tomcat 6 and I have two webapps. One of them is webapp1, and the other is webapp2. From the filter inside webapp2 I am trying to access another webapp ie webapp1. My filter code looks something like

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest)request;
    System.out.println("requeted path = " + req.getRequestURI());

    ServletContext othercontext = confg.getServletContext().getContext("/webapp1");
    RequestDispatcher dispatcher = othercontext.getRequestDispatcher(req.getRequestURI());
    dispatcher.forward(request, response);
    chain.doFilter(request, response);
}

Any idea what I'm doing wrong? I always get null as the value of othercontext.

+5
source share
2 answers

Set the value of crossContext = "true" in the server.xml file. See the documentation for the context container.

true, , ServletContext.getContext() - - . false ( ) , getContext() null.

+9

Apache Tomcat 8.0.27. server.xml context.xml tomcat crossContext Context.

0

All Articles