• 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

ClassCastException in jsp

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic