• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How can I pass two objects to a servlet from an applet?

 
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an applet that attempts to pass two objects to a servlet: 1. An array list, and 2. A simple string.
In the servlet, I have code that tries to read both objects (sent from the applet) like this:
inputFromApplet = new ObjectInputStream(request.getInputStream());
classSchedule = (ArrayList) nputFromApplet.readObject();
String whatToDo = (String) inputFromApplet.readObject();
=================
The applet passes the objects to the servlet like this:
utputToServlet = new ObjectOutputStream(
connection.getOutputStream());
outputToServlet.writeObject(list);
outputToServlet.writeObject(preview);
.
.
.
================================
The problem is getting a response back from the servlet. It seems this method isn't working well. I get an error when trying to read the response from the servlet in the applet (though sometimes it seems to work OK).
=======
Can anybody advise me the best way to pass to objects to a servlet?
Thanks much.
-- Mike
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are on the right track. Some problems with applet/servlet communication come from such things as:
closing the connection by closing a Stream prematurely
not flushing an output stream
Bill
 
Mike London
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill.
I solved the problem by instead just sending one data structure, an array list, and using the zero-eth element as the "instruction" on what the servlet should do with the array list.
- Mike
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic