File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes ClassCast Exception of a Bean in JSP file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ClassCast Exception of a Bean in JSP file" Watch "ClassCast Exception of a Bean in JSP file" New topic

ClassCast Exception of a Bean in JSP file


Joined: Sep 03, 2001
Posts: 2
Greetings All,
I am getting an usual ClassCast exception in JSP file, which is working very well for some days.This makes me to restart the server.
I am in doubt, when an servlet,jsp ,bean working fine for days and in the middle how it began breakdown.
i have code in servlet like this.
com.StatusBean sbean=new com.StatusBean();

<%@ page import="com.StatusBean;"%>
com.StatusBean s_Bean=(com.StatusBean)request.getAttribute("Status");
in my statusbean
public class StatusBean extends Object implements Serializable{
//only setter and getter methods are here
What i am wondering is , how an application cannot work,which worked continuously for 3 months ,
in JSP file at line 3 i am getting ClassCast exception lime cannot convert com.StatusBean to com.StatusBean..
I tried to findout what type of object a request holds with getClass().getName() method it is giving com.StatusBean only,
But when i am getting exception at line 3..
thanx in advance,
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
What can happen is that if you recompile your JavaBean, the dynamic classloading facility of your webserver reloads the class. This is great, but of course existing instances (say held in the session or request) are no longer compatible and hence you get a ClassCastException.
Another possibility is that you somehow have two versions of the bean in your classpath.
Could any of these be your problem?
I agree. Here's the link:
subject: ClassCast Exception of a Bean in JSP file
It's not a secret anymore!