Communication Applet - Servlet

I have a problem with the connection between an Applet and a Servlet. I know a lot of messages have been posted about this topic but I did not find an answer to my problem.

I want to transmit Objects from an Applet to a Servlet and vice versa. Sending an object from the Servlet to the Applet works fine but the other way does not work. I have no idea why I don't even get an Exception. I installed the Sun Java Plugin for the IE and it does not work. So I tried it without the plugin and it worked. The problem is, that without the plugin creating Frames did not work. So I try to solve the problem with the connection.

Here is the source code:

APPLET: URL servletURL =new URL("http://host:8080/servlet/Servlet");

URLConnection servletConnection = servletURL.openConnection();

servletConnection.setDoOutput(true);

servletConnection.setDoInput(false);

servletConnection.setUseCaches(false);

servletConnection.setDefaultUseCaches(false);

servletConnection.setRequestProperty("Content-type","application/x-java-serialized-object");

OutputStream os = servletConnection.getOutputStream();

output =new ObjectOutputStream(os);

Object myObject=new Object();

output.writeObject(myObject);

output.flush();

output.close();

SERVLET: ObjectInputStream input =new ObjectInputStream(request.getInputStream());

Object receivedObject;

receivedObject = input.readObject();

input.close();

Thank you for in advance your help.

[1943 byte] By [liam100] at [2007-9-19]
# 1

Communicating between a servlet and applet is more of a cycle than just making a request.

1. An applet calls the servlet with it's outputstream

2. The servlet responds by reading with it's inputstream from the applet

3. The servlet writes back to it's outputstream to the applet

4. The applet reads and completes the process by reading from the inputstream.

From your code below, you do not read from the input stream. Try reading from it and using the example at:

http://forum.java.sun.com/thread.jsp?forum=33&thread=205887

Why the applet has to read from the input stream to complete the process I'm not sure, but I think it's because it's completing the call the servlet and closing the stream that the servlet opened to the applet. If you don't access the input stream on the applet side, the applet will keep waiting until it indefinately.

It may sound confusing, I may be wrong but I know that this is how I've managed to solve the problem.

Is someone who runs the forums able to post a ore detailed article or make this topic a bit more obvious at all on the Java trails?

Good luck,

Anthony

[tone] at 2007-7-5 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2
For a full explanation check out the QoW archives: http://developer.java.sun.com/developer/qow/archive/53/index.htmlIt's a more technical explanation than I can offer.Cheers,Anthony
[tone] at 2007-7-5 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3
I will try that. But I am still searching for the reason why it works fine on the standard IE but fails on the IE with the Sun Java Plugin.Thanks anyway.
liam100 at 2007-7-5 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
I tried it and it works well. Again, thank you very much.
liam100 at 2007-7-5 > top of java,Enterprise & Remote Computing,Web Tier APIs...