This has nothing to do with Tomcat.... it has to do with Java, serialization and OO.
What are you trying to persist because it looks like you are persisting what amounts to be an inner class to a JSP? Consider changing that to a simple JavaBean not considered an inner class to the compiled JSP and you'll be fine. You'll never be able to cast w4a$ddm2 into w4b$ddm2 or vice-versa, but you can cast an instance of w4a$ddm2 or w4b$ddm2 to their common type, if they have one. Just having the same code does not make then the same class when compiled. -----Original Message----- From: Wolfgang Orthuber [mailto:orthu...@kfo-zmk.uni-kiel.de] Sent: Monday, October 04, 2010 8:10 AM To: Tomcat Users List Subject: Serialization 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-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org