Hi David
Your Trick worked . i am so happy ( because i have stuck up for 1,2 days 8-D )
My original design is :
Servlet :
.Execute specified SQL statement to get a resultset
.stuff all the tuples in that resultset into a LinkedList variable
.store this LinkedList object into HttpSession
JSP :
.get LinkedList variable from session
.traverse all the objects in that linkedlist and display its contents in client browser
My self-defined record structure is like this :
package search.common;
public class strucZassiKangouItem implements ijava.io.Serializable {
public StringstrKangou;public StringstrKiji;public StringstrTitleCode;
public strucZassiKangouItem() {
strKangou= null ;
strKiji= null;
strTitleCode= null;
}
}//:-
My servlet program is like this :
...
objBean.execSql() ;
// Set Session Variable
session.setAttribute( Commondef.SEARCHFLAG , strSearchFlag) ;
session.setAttribute( Commondef.SEARCHSTRING, strSearchString) ;
session.setAttribute( Commondef.CURRENTPAGE, String.valueOf(objBean.getPageCurrent())) ;
session.setAttribute( Commondef.OPERATION, strOperation) ;
session.setAttribute( Commondef.TITLECODE, strTitleCode) ;
session.setAttribute( Commondef.DISPLAY, objBean.getByteArray()) ;
....
getByteArray Function is like ( note Query result has been stored in lstResult ):
public byte[]getByteArray() {
byte[]bArray = null ;
try {
ByteArrayOutputStreambaos= new ByteArrayOutputStream();
ObjectOutputStreamoOut= new ObjectOutputStream( baos ) ;
oOut.writeObject( new Integer( lstResult.size()) ) ;
for ( int iLoop = 0 ; iLoop < lstResult.size() ; iLoop ++ ) {
oOut.writeObject( lstResult.get( iLoop )) ;
}//end for
oOut.flush();
bArray= baos.toByteArray() ;
oOut.close() ;
}catch ( IOException e ) {
baseServlet.Log("IoException occured in getOutputStream()") ;
}
return bArray ;
}
My JSP is like :
...
byte[]bArray= (byte[])session.getAttribute(Commondef.DISPLAY ) ;
ByteArrayInputStream bais= new ByteArrayInputStream( bArray ) ;
ObjectInputStream oIn= new ObjectInputStream( bais );
...
<TABLE width="896" border="0" cellpadding="0" cellspacing="0">
<%
int iLoop= 0;
for ( iLoop = 0 ; iLoop < objCount.intValue(); iLoop ++)
{
strucZassiKangouItemobjItem= ( strucZassiKangouItem )(oIn.readObject()) ;
String strKangou= "";
String strKiji= "";
String strTitle= "";
if ( objItem.strKangou != null )
strKangou= new String ( objItem.strKangou.getBytes() , "JISAutoDetect");
else
strKangou= "";
if ( objItem.strKiji != null )
strKiji= new String ( objItem.strKiji.getBytes() , "JISAutoDetect");
else
strKiji= "";
if ( objItem.strTitleCode != null )
strTitle= new String ( objItem.strTitleCode.getBytes() , "JISAutoDetect");
else
strTitle= "";
%>
<TR>
<TD width="490" height="88"><B><%=strKangou%></B>
<TABLE width="320" border="0">
<TR>
<TD><FONT size="2"><%=strKiji%></FONT></TD>
<TD align="right" valign="bottom"><FONT size="2"></FONT></TD>
</TR>
</TABLE>
</TD>
....
I think te problem is Classloader. i am using TOMCAT3.2.1.
It seems that tomcat use different classloader to load my servlet & jsp .Even i have verfied the object class name is the same by using Reflect API , there is always a ClassCastException thrown
thousands thanks again .
ZY