Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet to Servlet Communication

 
Nathalie Doremieux
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to send a Vector from an applet to a servlet.
I have no problem with IE. But it doesn't work with Netscape(4.7x & 6.x).
Any example would be great.
 
Tim Holloway
Saloon Keeper
Posts: 18362
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you sending it? If you're serializing, you could be having problems with differing versions of serialization between the client and server.
 
Nathalie Doremieux
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I am using to send the Vector:
URL url = new URL(getDocumentBase(),
"../servlet/myservlet.Applet2Servlet?action=selectedClassifications");
URLConnection urlconnection = url.openConnection();
urlconnection.setDoInput(true);
urlconnection.setDoOutput(true);
urlconnection.setUseCaches(false);
urlconnection.setDefaultUseCaches(false);
urlconnection.setRequestProperty("Content-Type", "multipart/form-data");//Netscape Bug
urlconnection.setAllowUserInteraction(false);
ObjectOutputStream objectoutputstream = new ObjectOutputStream(new GZIPOutputStream(urlconnection.getOutputStream()));
System.out.println("trying to send");
Vector objs = new Vector();
objs.addElement(selected);
objs.addElement(expanded);
objectoutputstream.writeObject(objs);
objectoutputstream.flush();
objectoutputstream.close();
 
Tim Holloway
Saloon Keeper
Posts: 18362
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
writeObject is part of the serialization mechanism, so it's likely that your sending serializer is incompatible with your receiving serializer. A better bet is to simply send everything as text:

where convertToObject() is a method you write to undo the "toString" on the sending side (if desired).
An industrial-strength version might send the vector size as a number on the first line (preceeding the data lines) so you can optimally preallocate the Vector (or use an Array object, which is faster).

[This message has been edited by Tim Holloway (edited October 17, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic