File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Question about passing objects between servlet and jsp ( getAttribute/setAttribute ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question about passing objects between servlet and jsp ( getAttribute/setAttribute )" Watch "Question about passing objects between servlet and jsp ( getAttribute/setAttribute )" New topic
Author

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

zheng yu
Greenhorn

Joined: Apr 25, 2001
Posts: 28
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

Joined: Oct 17, 2001
Posts: 4313

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).]


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
 
 
subject: Question about passing objects between servlet and jsp ( getAttribute/setAttribute )