Forums Register Login

ClassCastException in jsp

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2139 times.
Similar Threads
how to get the value saved in request scope in a servlet into a jsp page
Problem with jsp:setAttribute tag
ClassCastException
Mixing of code - raw and generic
q on JSTL
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:06:57.