You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Liu, Xiaoyan" <xl...@CapitalThinking.com> on 2003/05/06 23:32:38 UTC

jsp:include pages under another context and Webapp Classloader

Hi, all,

Please help me clarify this, I'm a bit confused.

There are two contexts deployed in my tomcat server.xml, webapp1 and
webapp2.

test.jsp under webapp1 looks like this:

<%@ page import="com.test.TestObject" %>

<% TestObject o = new TestObject();
      request.setAttribute("test", o);
%>

<jsp:include page="/webapp2/test_include.jsp" flush="true" />
----------------------------------------------------------------------------
--------------------------------
and test_include.jsp looks like:

<%@ page import="com.test.TestObject" %>

<% TestObject o2 = (TestObject)request.getAttribute("test");
      if (o2 == null) o2 =  new TestObject();
%>

ClassLoader for o2: <%= o2.getClass().getClassLoader().hashCode() %>
----------------------------------------------------------------------------
--------------------------------
The observation:
If I access webapp2/test_include.jsp, the classloader for 'o2' is a
different one
(for webapp2). This is expected. However, 

If I access webapp1/test.jsp, the classloader for 'o2' is the one for
webapp1, not
for webapp2? Why is that? I was kind of expecting a 'ClassCastException',
but
it didn't happen.  Does this test makes sense?

TestObject class is deployed separately under each webapp/WEB
-INF/lib directory.


Thanks for your help.


Liu