aspose file tools*
The moose likes JSP and the fly likes ClassCastException in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "ClassCastException in jsp" Watch "ClassCastException in jsp" New topic
Author

ClassCastException in jsp

Jo Lee
Ranch Hand

Joined: Jun 26, 2001
Posts: 35
I have a class method which returns an arraylist. In my jsp page I used java.util.ArrayList aList = thisclass.getList();
and then iterate it through to create a table of data display. This page comes up after the user validation is done.
when I run the jsp page first time, it all runs ok. However, if I try to click on a link to the same jsp page from another page, it will return an Http status 500 error with ClassCastException.
Hope I have made this clear.
Jo
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
You need to set up an errorPage url for the JSP - on your error page JSP you can have:
exception.printStackTrace( out );
which should lead you to exactly the cause. You may have to look at the .java file created by the JSP engine to make sense of line numbers.
Bill
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Depending on the server you are using, I'm guessing its a ClassLoader problem. If you do a search in Javaranch for +ClassLoader +JSP +ClassCastException it should return some of the previous discussions.
Dave
Jo Lee
Ranch Hand

Joined: Jun 26, 2001
Posts: 35
thanks Bill;
I created the following error page:
<%@page contentType="text/html"%>
<%@ page isErrorPage="true" %>
<html>
<head><title>JSP Page</title></head>
<body>
<p> mypage reported the following error</p>
<%= exception %> this problem occured in the following place;
<pre><% exception.printStackTrace(out); %></pre>
</body>
</html>
The compiler complains that :
error$jsp.java [76:1] cannot resolve symbol
symbol : method printStackTrace (javax.servlet.jsp.JspWriter)
location: class java.lang.Throwable
exception.printStackTrace(out);
^
1 error
while running in tomcat -4.0.4 , it complains;
An error occurred at line: 10 in the jsp file: /error.jsp
Generated servlet error:
C:\jstlPackage\work\Standalone\localhost\MySite\error$jsp.java:70: Incompatible type for method. Can't convert javax.servlet.jsp.JspWriter to java.io.PrintWriter.
exception.printStackTrace(out);
^
However, when change the error page with the following line;
<% exception.printStackTrace(new PrintWriter(out)); %>
I get the following compiler error:
error$jsp.java [76:1] cannot resolve symbol
symbol : class PrintWriter
location: class org.apache.jsp.error$jsp
exception.printStackTrace(new PrintWriter(out));
^
1 error
and the folloing tomcat error:
An error occurred at line: 10 in the jsp file: /error.jsp
Generated servlet error:
C:\jstlPackage\work\Standalone\localhost\MySite\error$jsp.java:70: Class org.apache.jsp.PrintWriter not found.
exception.printStackTrace(new PrintWriter(out));
^
if change to the following;
<% exception.printStackTrace(new JspWriter(out)); %>
I get another compiler error:
error$jsp.java [76:1] javax.servlet.jsp.JspWriter is abstract; cannot be instantiated
exception.printStackTrace(new JspWriter(out));
^
1 error

I am completely lost in the mist. Need urgent help.
Jo
Jo Lee
Ranch Hand

Joined: Jun 26, 2001
Posts: 35
I did a search on google and javaranch about this classcastexception, it seems it is a problem, however, is there a solution?
I have this problem now, when I try to pass a Map object as session Attribute, even if I do not do that, it seems that if I just use the Map object in the jsp page and when I try to reload the page, it gives classcastexception, I use tomcat4.0.4
Any more pointer or solution is highly appreciated.
thanks
 
jQuery in Action, 2nd edition
 
subject: ClassCastException in jsp