This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Communication between Servlet and Applet

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shah Devang
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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


Thanks
Devang Shah
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings are what HTTP uses anyway internally, so you can send those directly, without the need to serialize/deserialize anything.
 
Shah Devang
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
There's a way to do it better - find it. -Edison. A better tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic