Bug 10544

Summary: crossContext for servlets not working
Product: Tomcat 4 Reporter: J F <jfienberg>
Component: Servlet & JSP APIAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: critical CC: chrigri, christian.wicke
Priority: P3    
Version: 4.0.4 Final   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: This a suggestion to fix Bug 10544

Description J F 2002-07-08 05:18:32 UTC
I am not able to reference resources from one webapp to another in the same 
host. I have previously successfully used the configuration (in 4.03):

 	  <DefaultContext crossContext="true"/> 

I also tried adding crossContext="true" to the contexts for each webapp in the 
host. This made no change.

The following (from a page in the ROOT context) gets a 404 error and the host 
log shows the error is for the URI /test.jsp (root cause: 
java.io.FileNotFoundException: /test.jsp), where it previously successfully 
forwarded to the page /webapp2/test.jsp:

	RequestDispatcher dispatcher = ctx.getContext
("/webapp2").getRequestDispatcher("/test.jsp");
        dispatcher.forward(request, response);

For any value I use in ctx.getContext("/asdas") that begins with a "/", I get 
the current context (non-null), EVEN if the value does not match any existing 
context.
Comment 1 Christer Grimsaeth 2002-08-07 15:57:30 UTC
I can confirm that this is also happening here.

From a page in the root context ("/") it does not matter what you put in to 
getContext("/anyThingWillDo"), it always returns the current context (which is 
the roor context).

Comment 2 Chrstian Wicke 2002-10-10 06:51:40 UTC
I also found this problem in tomcat 4.0.6 and tomcat 4.1.12.
Comment 3 Chrstian Wicke 2003-01-16 12:15:52 UTC
Created attachment 4462 [details]
This a suggestion to fix Bug 10544
Comment 4 Chrstian Wicke 2003-01-16 12:17:29 UTC
Hello,

I found the bug:
src/share/org/apache/catalina/core/ApplicationContext.java line 445 (in tomcat 
4.1.18):
        if ((contextPath.length() > 0) && (uri.startsWith(contextPath))) {
            return (this);
        }
since the root context is "/" every uri starts with the contextPath and hence 
the root context is returned again.
To fix it the 0 has to be replaced with 1.
I attached a patch.

Christian
Comment 5 Martin Algesten 2003-01-16 13:57:53 UTC

*** This bug has been marked as a duplicate of 13040 ***