This discussion is archived
4 Replies Latest reply: Dec 7, 2011 12:41 PM by DrClap RSS

Applet Servlet communication via serialization

903779 Newbie
Currently Being Moderated
I serialized an object containing a JTable to and from a file
without any problem.

Now I ran the same serialization over the net from servlet to
applet and get now a security exception. The table data are
simple Strings.
If i remove the JTable from the serialized object the communicaton
works fine.

I use the DefaultTableModel.
  • 1. Re: Applet Servlet communication via serialization
    EJP Guru
    Currently Being Moderated
    a security exception
    Such as?
  • 2. Re: Applet Servlet communication via serialization
    DrClap Expert
    Currently Being Moderated
    It doesn't make sense to serialize a JTable, or any GUI component, anyway. For one thing it has listeners which are specific to the current running JVM, so deserializing it elsewhere makes those listeners meaningless. So don't do that. Just serialize the TableModel and put it back into your running JTable when you deserialize it.
  • 3. Re: Applet Servlet communication via serialization
    903779 Newbie
    Currently Being Moderated
    Sorry for the delay.

    Here is the stack trace of my error message ( a bit truncated ) :

    perhaps the line marked bold is somewhat responsible.
    Is there a way to deactivate this EventListenerList ?
    What is it used for ?

    I get the error even if I only instantiate an empty table ( without any explicit model ).

    java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.swing.table)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPackageAccess(Unknown Source)
         at sun.plugin2.applet.Applet2SecurityManager.checkPackageAccess(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at java.io.ObjectInputStream.resolveClass(Unknown Source)
         at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
         at java.io.ObjectInputStream.readClassDesc(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at javax.swing.event.EventListenerList.readObject(Unknown Source)
         at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
         at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
         at javax.swing.JTable.readObject(Unknown Source)
  • 4. Re: Applet Servlet communication via serialization
    DrClap Expert
    Currently Being Moderated
    That's what I just said. It doesn't make sense to serialize a JTable because it contains things like that. Besides your server can't do anything with the GUI anyway. All it needs is the data, which is the TableModel. So just serialize that.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points