Bug 10544 - crossContext for servlets not working
Summary: crossContext for servlets not working
Status: RESOLVED DUPLICATE of bug 13040
Alias: None
Product: Tomcat 4
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: 4.0.4 Final
Hardware: PC All
: P3 critical with 4 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-08 05:18 UTC by J F
Modified: 2005-03-20 17:06 UTC (History)
2 users (show)



Attachments
This a suggestion to fix Bug 10544 (752 bytes, patch)
2003-01-16 12:15 UTC, Chrstian Wicke
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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 ***