• 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Applet/Servlet communication failing...

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a rather annoying issue communicating between an Applet and a servlet. The basic flow of information is as follows:
The applet constructs a HashMap of criteria information for a query (name/value pairs, like "productCode" => "1001233"). This HashMap is transfered to the servlet through a POST request. This part works fine.
The servlet receives this criteria, and performs a query, and attempts to return back a custom object (named FormulaMapBean (which also contains references to ComponentBean and FormulaBean)). This part fails. I've ran with tracing of 5, and found the following in the Java console:
Reading bean
Connecting http://localhost:8082/standards/classes/com/kellogg/london/common/beans/standards/FormulaMapBean.class with no proxy
Connecting http://localhost:8082/standards/classes/com/kellogg/london/common/beans/standards/FormulaMapBean.class with cookie "JSESSIONID=D85890B193E5A4A8F0F0D0662226A577"
Connecting http://localhost:8082/standards/classes/com/kellogg/london/common/beans/standards/FormulaBean.class with no proxy
Connecting http://localhost:8082/standards/classes/com/kellogg/london/common/beans/standards/FormulaBean.class with cookie "JSESSIONID=D85890B193E5A4A8F0F0D0662226A577"
Connecting http://localhost:8082/standards/classes/com/kellogg/london/common/beans/standards/ComponentBean.class with no proxy
Connecting http://localhost:8082/standards/classes/com/kellogg/london/common/beans/standards/ComponentBean.class with cookie "JSESSIONID=D85890B193E5A4A8F0F0D0662226A577"
Finding information ...
Releasing classloader: sun.plugin.ClassLoaderInfo@82751, refcount=0
Done ...
java.lang.ClassNotFoundException: com.kellogg.london.common.beans.standards.FormulaMapBean
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(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.readObject(Unknown Source)
at com.kellogg.london.applets.standards.AppletServletCommunicator.readBean(AppletServletCommunicator.java:179)
at com.kellogg.london.applets.standards.FormulaQueryApplet.init(FormulaQueryApplet.java:47)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 17 more

What I find really strange, however, is that this works perfectly fine when using a Java class (I've tried changing the HashMap, and returning it, and that works perfectly fine, however, returning these custom objects doesn't).
Any ideas?
These objects are serializable. They're initially loaded (by the servlet) from a web service, and this works fine as well! It's the transition from Servlet to Applet that keeps screwing up, and I dont understand why.
General flow (in Applet):
System.out.println("Reading bean");
Object o = comm.readBean(); // fails if o is a FormulaMapBean
General flow (in servlet):
Object o = comm.readBean(); // criteria hashmap (works!)
FormulaMapBean fmb = getFormula(map);
where comm is a class I wrote with the following relevant methods:
public void startPost(String type) {
try {
URL testServlet = new URL( servletAddress );
servletConnection = testServlet.openConnection();
// make sure we can both read and write to servlet
// Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
// Specify the content type that we will send binary data
servletConnection.setRequestProperty("Content-Type", type);
servletOutputStream = servletConnection.getOutputStream();
// send your data to the servlet
} catch(Exception e) {
public void endPost() {
try {
servletInputStream = servletConnection.getInputStream();
} catch(Exception e) {
public void sendBean(Object o) {
try {
ObjectOutputStream outputToServlet = new ObjectOutputStream(servletOutputStream);
} catch(Exception e) {
public Object readBean() {
Object o = null;
try {
ObjectInputStream inputFromServlet = new ObjectInputStream(servletInputStream);
o = inputFromServlet.readObject();
} catch(Exception e) {
return o;

Any help would be greatly appreciated (and I appologize for the long post... this stuff's fairly new to me, so I'm not sure all what's relevant). It looks like it's a case of having to somehow 'Register' with the ObjectInputSteam where the FormulaMapBean.class is located... except that, from the Java Console output (first few lines) it seems to me that is does, indeed, know where it is!
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put the "com.kellogg.london.common.beans.standards.FormulaMapBean" class in the classpath for the applet (like in the JAR file it's loaded from), or somewhere in the codebase. There are other ways to make it dynamically load - but it's easiest just to put it with the applet code in a jar.
Jeff Weeks
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers! All working now
I thought I'd already done that
I was loaded my applet from the /webcontext/classes directory which I had simply assumed was the standards.war:/web-inf/classes directory, and that all the classes were in there. Obviously that wasn't the case
Attractive, successful people love this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic