File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Applet to Servlet Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet to Servlet Communication" Watch "Applet to Servlet Communication" New topic
Author

Applet to Servlet Communication

Nathalie Doremieux
Greenhorn

Joined: Oct 16, 2001
Posts: 2
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

Joined: Jun 25, 2001
Posts: 16014
    
  20

How are you sending it? If you're serializing, you could be having problems with differing versions of serialization between the client and server.


Customer surveys are for companies who didn't pay proper attention to begin with.
Nathalie Doremieux
Greenhorn

Joined: Oct 16, 2001
Posts: 2
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

Joined: Jun 25, 2001
Posts: 16014
    
  20

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).]
 
Consider Paul's rocket mass heater.
 
subject: Applet to Servlet Communication