Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about passing objects between servlet and jsp ( getAttribute/setAttribute )

 
zheng yu
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TOMCAT3.2.1 + Linux + Oracle 8.1.7
I developed a servlet that store query result( a self-defined object ) in session , and use getRequestDispatcher().forward(..) to a JSP file . my problem is i always get ClassCastException.
can some body shed some light on it ?
My self-defined object is declared as follow
12 package search.db ;
13
14 public class strucZassiKangouItem extends Object{
15 public String strKangou ;
16 public String strKiji ;
17 public String strTitleCode;
18 public strucZassiKangouItem() {
19 strKangou = null ;
20 strKiji = null ;
21 strTitleCode= null ;
22 }
23 }//~:-
in my servlet program :
163 objRs.execSql() ;
164
....
169 // Set Session Variable
....
188 session.setAttribute( Commondef.DISPLAY, objRs.getLstResult()); // Store query result into session object
....
203 getServletContext().getRequestDispatcher("/jsp/ZassiKangou.jsp").forward(req, res);

my JSP is like this :
objResult = (LinkedList)session.getAttribute (Commondef.DISPLAY) ;
.....
everytime i use
strucZassiKangouItem objItem =( StrucZassiKangouItem )objResult.getFirst() ;
there is a ClassCastException .

i dont know why .
Thanks in advance
ZY

 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
run a quick test on your class to make sure that the object you're getting back really is of type StrucZassiKangouItem. It's possible that the first item you're getting back from your session is of another type.

[This message has been edited by Jessica Bradley (edited October 18, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic