permaculture playing cards*
The moose likes Servlets and the fly likes Class cast exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Class cast exception" Watch "Class cast exception" New topic
Author

Class cast exception

Sujith Nair
Greenhorn

Joined: Nov 30, 2000
Posts: 4
I am using JRun 3.0 and using servlets and jsp's. The JSP's are however behaving in an unpredictable manner and throwing classcast exception every now and then. At times it works and at times it throws this error. Could somebody help out??
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Do these exceptions always happen at the same place in the code? Could you copy a few exception prints/stack traces here so we can see a bit mre about the error.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Sujith Nair
Greenhorn

Joined: Nov 30, 2000
Posts: 4
Hi Iam now writing the error it generates on the browser
java.lang.ClassCastException
at jrun____ScipDev____jsp____SeraNews____Quiz12ejsp23._jspService(jrun____ScipDev____jsp____SeraNews____Quiz12ejsp23.java, Compiled Code)
at allaire.jrun.jsp.HttpJSPServlet.service(HttpJSPServlet.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(JRunNamedDispatcher.java, Compiled Code)
at allaire.jrun.jsp.JSPServlet.service(JSPServlet.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java, Compiled Code)
at QuizServlet.service(QuizServlet.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(JRunNamedDispatcher.java, Compiled Code)
at allaire.jrun.servlet.Invoker.service(Invoker.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled Code)
at allaire.jrun.servlet.JvmContext.dispatch(JvmContext.java, Compiled Code)
at allaire.jrun.jrpp.ProxyEndpoint.run(ProxyEndpoint.java, Compiled Code)
at allaire.jrun.ThreadPool.run(ThreadPool.java, Compiled Code)
at allaire.jrun.WorkerThread.run(WorkerThread.java, Compiled Code)
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I haven't worked with JRun, only with Java Web Server. However, I ran into the same problem, and needed to do two things: 1. Originally, I had put my JSPs in a package, and I had to take them out of the package. 2. I had to move the Java classes (servlets) from the servlets folder to the classes folder. Hope this helps.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
ClassCastException will occur due to runtime casting errors. It occurs when we try to cast an object to a class type which is incombatible. You may have to check your code once more I think.
regds
maha anna
I just give you an example:


[This message has been edited by maha anna (edited December 04, 2000).]
Paul Wetzel
Ranch Hand

Joined: Nov 02, 1999
Posts: 107
Using weblogic I ran into class cast exception. It was because the servlet class loader were loading the class. Here is a link to what weblogic has to say about this. It may help, I dont know...worth a try http://www.weblogic.com/docs45/classdocs/API_servlet.html#classcastexception
best of luck paul
Sujith Nair
Greenhorn

Joined: Nov 30, 2000
Posts: 4
Hi all,
Thanks a lot. Yeah it definitely is a classloader issue. We have got the work around by putting the beans in the JRun's classpath. I just looked at the documentation at weblogic. They definitely have done a good job. Their explanation I believe will be valid for most of the Application servers available.
Taha Mohamed
Greenhorn

Joined: Oct 26, 2000
Posts: 6
Dear All,
There is a simple solution for this. Try using scope="page" (instead of scope="session") in your <jsp:UseBean> Tag.
This will make sure that the class is loaded for every page instead of once every session.
If the scope is session, the servlet class loader will load the class only once per session. So the object in the later page will be casted to the class of the previous session which is incompatable (unlike the object in the previous page).
Please let me know if my statement is incorrect.
------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class cast exception
 
Similar Threads
Deploytool
session and exception handling in jsp and servlet?
Limit of JSP page to Compile
How to pass parameters from one JSP to another JSP
Frame synchronization forJSP's