This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!