tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cory L Hubert" <>
Subject RE: Wierd Casting Problem. Tomocat Bug?
Date Sun, 29 Apr 2001 18:13:53 GMT
	I found out the problem.  This looks like an extreme hack though.

	<$=((member) ((Object)e.nextElement()) ).getFname()%>

	Works.   But why do I have to cast to an Object before I cast it back to
it's appropiate type.   My only guess is that the Servlet DownCast the
Vector to an Object (because there is some reflection that goes on) before
setting the Attribute and passing it to JSP.
	But the actual member objects are put in the Vector as member Objects.
Any Ideas?  Does anyone thing it's wierd that you have to cast to and Object
then to the Type.
	I believe this isn't a Java Bug it may be a Tomcat Bug.  Because I don't
have to cast to an Object, if I am casting to member objects in the Servlet.

-----Original Message-----
From: Cory L Hubert []
Sent: Sunday, April 29, 2001 3:46 AM
Subject: Wierd Casting Problem.

	Ok.  Here is the problem.  I am using Model 2 Architecture.  So my Servlet
handles all the biz logic and pushes the results that are then displayed by
jsp pages.

		Within a jsp page I grab my vector from the request like so..

		Vector mems =(Vector)request.getAttribute("response");

			Then I try to loop around it and cast it to the appropiate Object. Like
		for (int i=0; i < mems.size(); i++) {

			member m = (member)mems.get(i);

		I get a ClassCastException.   But when I do a toString on the Object
itself without casting, it specifies the package name of the object that I
am trying to cast to.

		To make matters wierder.  When I do a getClass().isInstance(THE OBJECT I
WANT TO CAST TO) it returns false?

		What is going on here?  Is this some classLoader issue?

		Some tips that might help figure this issue out......

			I am importing the class I am casting, in the JSP page. like so..

			<%@page import="thepackage.member, java.util.*"%>

			And the class itself isn't in a jar.  It's in the WEB-INF/classes

			I also changed the container from a Vector to an ArrayList and got the
same results.

			And I can instantiate the member object itself and use it in the jsp

		Any ideas?  Please.  Someone, HELP!!!

View raw message