0

I am getting an Object from session and typecasting to some User Object. Lets say like this:

A a =(A)session.getAttribute("A"); //Class Cast Exception

Background: I am going to jsp from a normal java class by requestDispatch.forward(request,response) In Java, If I do the same casting , it works fine , but in JSP(scripplet:I know a bad coding but its a legacy application, cant help it), Its not working

Analysis:

  1. The Object which I am getting from session in jsp, doesn't pass isInstanceOf test ( its also a worry) ( But it pass this test in java )

  2. If I do class equal comparision, it also fails ( But it pass this test in java )

  3. So I checked the classloader instance for Class A in java as well as in JSP, And I see both are different instances.

So my question is how do I make sure that class loader instance will be same? Or am I analysing properly? What else shold I check more? Any hit n trail u can suggest for same?

P.S> 1.I am using weblogic 10.3.6 2. I am deploying as a single war ( so no question on modifying weblogic-application.xml for class loading hierarchy.) 3. Its a simple java-servlet-jsp legacy application, so I have no liberty of using anymvc framework 4. I have already marked my DTOs as Serializable with serialveruuid 5. It works fine in first go. But second go onwards, it starts failing

ekostadinov
  • 6,880
  • 3
  • 29
  • 47
Vivek Shukla
  • 711
  • 9
  • 18
  • 1
    possible duplicate of [ClassCastException when casting to the same class](http://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class) – Joe Sep 15 '14 at 07:14
  • @joe I have gone through the article, not helping me. Do you have any concrete solution for that? or if you need further details to diagnose the problem,let me know – Vivek Shukla Sep 15 '14 at 11:33
  • Your problem is the different classloaders. Identifying more specifically which classloaders they are would be a good next step. – Joe Sep 15 '14 at 11:56
  • I am looking for an detailed approach/answer. @Joe - Its too abstract for me to comprehend. Anyways thanks a lot for valuable suggestion. – Vivek Shukla Sep 16 '14 at 05:47

0 Answers0