This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Applets and the fly likes Communication between Servlet and Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "Communication between Servlet and Applet " Watch "Communication between Servlet and Applet " New topic
Author

Communication between Servlet and Applet

Shah Devang
Greenhorn

Joined: Jul 27, 2006
Posts: 12
Hi,

I have a HTML page that has some links. When I click a link, I want to display the applet and its data differs depending upon the element selected. To achieve this, I made an HTTP call to the servlet and passed it the element selected as parameter. Depending upon the element selected I create a swing object that I want to render on the applet. This object I pass to the applet and add this to the applet.

But this is not working. I am getting the following exception on the Java console :

java.io.InvalidClassException: javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = 5896976265092562486, local class serialVersionUID = 7917968344860800289
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(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.readObject(Unknown Source)
at com.accurev.HelloWorldApplet.readInputStream(HelloWorldApplet.java:78)
at com.accurev.HelloWorldApplet.sendObject(HelloWorldApplet.java:51)
at com.accurev.HelloWorldApplet.init(HelloWorldApplet.java:28)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at com.accurev.HelloWorldApplet.init(HelloWorldApplet.java:31)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

------------------------------------------------------

The code that I have implemented goes like this :




The DiffPanel object extends JPanel and implements Serializable.

Can anyone please help.

Thanks
Devang Shah
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35248
    
    7
In order to serialize objects from one JVM to another, both need to agree on the exact version of the object transferred. It looks like the applet JVM is a different version than the servlet JVM, and the object you're trying to transfer is not the same, and thus can not be deserialized.

Instead of transferring an instantiated object, why don't you pass all the information necessary to instantiate it in the applet?

Alternatively, you could try to serialize by using the java.beans.XMLEncoder/Decoder classes, which are less prone to version conflicts.


Android appsImageJ pluginsJava web charts
Shah Devang
Greenhorn

Joined: Jul 27, 2006
Posts: 12
Hi,

So can I atleast send string objects from servlet to the applet ?


Thanks
Devang Shah
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35248
    
    7
Strings are what HTTP uses anyway internally, so you can send those directly, without the need to serialize/deserialize anything.
Shah Devang
Greenhorn

Joined: Jul 27, 2006
Posts: 12
Hi,

What I am trying to show in Applet is a diff window. The diff tool gives me a swing based window ouput showing the diff of the two files. Now I want this window to be shown on the clients browser. Now since its diff, the data size can be huge. Can you please show some pointers how do I achieve this ?

Thanks
Devang Shah
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35248
    
    7
What exactly is the problem - integrating a Swing application in an applet or retrieving the files from the server? Does the application have an API that can be used for embedding purposes?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Communication between Servlet and Applet
 
Similar Threads
servlet/applet communication problem
receiving serialized object from servlet to applet
Applet and Servlet connection
Signed applet talking to server other than its own
Applet servlet communication