You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Serge Huber <sh...@xo3.com> on 2001/08/07 18:34:52 UTC

Problem in JasperLoader ?

Hi all,

I am using a RequestDispatcher to do a cross context include to a JSP. The 
problem is there seems to be a problem in the JasperLoader implementation. 
Let me explain quickly the configuration :

contextA :
- does a 
getContext("/contextB").getRequestDispatcher("path/file.jsp").include(request, 
response) call

contextB :
- contains the path/file.jsp file that contains an @page 
import="com.xo3.MyClass" and of course uses the MyClass class...
- contains the WEB-INF/classes/com/xo3/MyClass

When the dispatch occurs, the JSP file is compiled and executed, but it 
complains that it can't load the MyClass class. I suspect the following 
lines in src\jasper\src\share\org\apache\jasper\servlet\JasperLoader.java :

	// Class is in a package, delegate to thread context class loader
	if( !name.startsWith(Constants.JSP_PACKAGE_NAME) ) {
             ClassLoader classLoader = null;
	    if (System.getSecurityManager() != null) {
                  classLoader = 
(ClassLoader)AccessController.doPrivileged(privLoadClass);
             } else {
	        classLoader = 
Thread.currentThread().getContextClassLoader(); 
<----------------------------------------------------
             }
             clazz = classLoader.loadClass(name);
	    if( resolve )
		resolveClass(clazz);
	    return clazz;
	}

The problem here is that from what I understand from the source the current 
thread context class loader is never changed from contextA to contextB. So 
that when JasperLoader executes in contextB, it actually tries to load 
classes using the class loader of contextA.

Did I miss something in configuration or is this a bug ?

Best greetings,
	Serge Huber.
	shuber@xo3.com


Re: Problem in JasperLoader ?

Posted by Serge Huber <sh...@xo3.com>.
Ok thanks a lot.

Yes I did miss the commit message (I have them filtered to another folder) 
! Thanks a lot for the quick fix !

Best greetings,
         Serge Huber...

At 09:25 08.08.2001 -0700, you wrote:
>2 is the only correct one, since if you forward to a servlet, it wouldn't
>work otherwise.
>The fix is already in the CVS (you missed the commit message apparently).
>
>I have a test case which I didn't add because it requires modifications to
>the tester.
>
>Remy


Re: Problem in JasperLoader ?

Posted by Remy Maucherat <re...@apache.org>.
> I'd be willing to help with this issue, but from my point of view there
are
> two possibilities :
>
> 1. We revert the JasperLoader changes back to parent.loadClass(name) call.
>
> 2. We modify Catalina to set the contextClassLoader during an include or a
> forward call.
>
> I still wonder which is the best approach, but I must say I don't quite
> understand why we have to store the class loader in the Thread. It seems a
> tad ugly to do it that way...

2 is the only correct one, since if you forward to a servlet, it wouldn't
work otherwise.
The fix is already in the CVS (you missed the commit message apparently).

I have a test case which I didn't add because it requires modifications to
the tester.

Remy


Re: Problem in JasperLoader ?

Posted by Serge Huber <sh...@xo3.com>.
I'd be willing to help with this issue, but from my point of view there are 
two possibilities :

1. We revert the JasperLoader changes back to parent.loadClass(name) call.

2. We modify Catalina to set the contextClassLoader during an include or a 
forward call.

I still wonder which is the best approach, but I must say I don't quite 
understand why we have to store the class loader in the Thread. It seems a 
tad ugly to do it that way...

Best greetings,
         Serge...

At 13:53 07.08.2001 -0700, you wrote:
>Quoting Serge Huber <sh...@xo3.com>:
>
> > Hi all,
> >
> > I am using a RequestDispatcher to do a cross context include to a JSP.
> > The
> > problem is there seems to be a problem in the JasperLoader
> > implementation.
> > Let me explain quickly the configuration :
> >
> > contextA :
> > - does a
> > 
> getContext("/contextB").getRequestDispatcher("path/file.jsp").include(request,
> >
> > response) call
>
>I just checked and cross-context includes and forwards have a problem.
>You can use a redirect as a workaround with b6.
>
>Remy


Re: Problem in JasperLoader ?

Posted by Remy Maucherat <re...@betaversion.org>.
Quoting Serge Huber <sh...@xo3.com>:

> Hi all,
> 
> I am using a RequestDispatcher to do a cross context include to a JSP.
> The 
> problem is there seems to be a problem in the JasperLoader
> implementation. 
> Let me explain quickly the configuration :
> 
> contextA :
> - does a 
> getContext("/contextB").getRequestDispatcher("path/file.jsp").include(request,
> 
> response) call

I just checked and cross-context includes and forwards have a problem.
You can use a redirect as a workaround with b6.

Remy