• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCast Exception of a Bean in JSP file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
sbean.setMessage("HAHA");
sbean.setValue("DDD");
sbean.setID("100");
request.setAttribute("Status",sbean);
getServletContext().getRequestDispatcher("/x.jsp").forward(request,response);

//INjSP
<%@ page import="com.StatusBean;"%>
System.out.println("1");
com.StatusBean s_Bean=(com.StatusBean)request.getAttribute("Status");
System.out.println("2");
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,
aus_rayaku@yahoo.com
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Simon
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic