tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wolfgang Orthuber <orthu...@kfo-zmk.uni-kiel.de>
Subject Re: Serialization
Date Mon, 04 Oct 2010 13:38:20 GMT
  w4a.jsp and w4b.jsp are the names of two different jsp files. Both 
contain
<%@ include file="wtovedi.jsp" %>
and the file wtovedi.jsp contains the listed read and write code with 
the definitions of ddm2. ddm2 is a rather complex object of objects, but 
it contains no reference to w4a.jsp or w4b.jsp which are just filenames.

Wolfgang


Am 04.10.2010 13:08, schrieb Ronald Klop:
> What does ddm2 look like? Does it have a reference to the jsp object?
>
> Ronald.
>
>
> Op maandag, 4 oktober 2010 15:10 schreef Wolfgang Orthuber 
> <orthuber@kfo-zmk.uni-kiel.de>:
>>
>>
>>   Hello,
>>
>> my tomcat version is 5.5.17, my question concerns serialization of 
>> objects, below is a code section for writing and reading an object. 
>> If I call write immediately before read:
>> d5.write();
>> d5.read();
>>
>> then all works fine, but if I use only read (on an formerly written 
>> file) with the same code included in another program module, I got 
>> the exceptions like this:
>> java.lang.ClassCastException: org.apache.jsp.w.w4a_jsp$1ddm2 cannot 
>> be cast to org.apache.jsp.w.w4b_jsp$1ddm2
>>
>> in which w4a.jsp and w4b.jsp are two different modules which include 
>> the same code for read and write. The name of the program module is 
>> stored in the serialized object, but the name of the program module 
>> does not matter, because both modules include the same code.
>>
>> Do you know a simple solution which avoids the exception?
>>
>> Wolfgang
>>
>>
>>
>> The code section with read and write:
>>
>>
>> class dm5t implements Serializable {
>>      public ArrayList<ddm2>    v5;
>>
>>      public dm5t () {  v5 = new ArrayList<ddm2> (); }
>>
>>      public String topicpath(){return 
>> getServletContext().getRealPath("")+"/tp/";}
>>
>>      public synchronized boolean write () {
>>          String fn=fntopics;
>>          boolean ok=true;
>>          try {
>>              String spath = topicpath();
>>
>>              FileOutputStream    fs = new FileOutputStream (spath+fn);
>>              ObjectOutputStream    os = new ObjectOutputStream    (fs);
>>              os.writeObject (v5);
>>              os.close ();}
>>          catch (IOException e) {ok=false;} return ok;}
>>
>>      public synchronized boolean    read () {
>>          String fn=fntopics;
>>          boolean ok=true;
>>          ArrayList<ddm2>    v5tmp=null;
>>          try {
>>              String spath = topicpath();
>>
>>              FileInputStream        fs = new FileInputStream (spath+fn);
>>              ObjectInputStream    os = new ObjectInputStream    (fs);
>>
>>              v5tmp = (ArrayList<ddm2>) os.readObject ();
>>              os.close ();
>>
>>          } catch (IOException e) {ok=false;}
>>          catch (ClassNotFoundException e) {ok=false;}
>>          if (ok)    if (v5tmp != null) v5=v5tmp;
>>          return ok;}
>> }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message