0

I earlier asked the question ,"How can I make Servlet send some data to the applet ?"

~Link here

The responses I got were , to convert that data to common transfer format for example xml,csv or use serialization. An advantage that was listed :

Those common transfer formats have the advantage that there are so many APIs/libraries available to convert between a complex Java object and a String or input/output stream in the common transfer format with a minimum of needed code. Finally you just write it to the output stream of the HTTP servlet response which will then be retrieved as input stream of the URL connection in the applet.

Because nobody mentioned that,I need to ask : Can't I make a call to the applet's function from the servlet that contains the data,and deliver the data to that applet ?

Are there any drawbacks with this ?

This is what I am doing right know :(I directly call the applet's function 'func')

// Snippet from the servlet

gdfd = new GetDataFromDatabase(queryString);
map = gdfd.getResult(); // Get the HashMap object from the bean
new PollForm().func(map); // Send the map object to the applet
Community
  • 1
  • 1
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • In general you can't. There's one server and there could be any number of running applet instances connected to it. It should generally work the other way around: the applet should ask the server for the data. – biziclop Jul 25 '12 at 14:21

1 Answers1

0

The applet and the servlet are running on different computers. There's also likely to be multiple instances of the applet (running in people's browsers) for a single instance of the servlet (running on your server).

Therefore they cannot directly call functions on each other, as they are not connected except via a network connection.

Calling new PollForm() in the servlet creates a new instance of the applet on the server - which is not very useful as nobody can see it.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207