I have a problem with servlet-applet communication and I wonder if anyone could help me. I want to pass a serialized object 'myObj' from the servlet to the applet. The applet calls the servlet. I'm using the following code:
----------SERVLET
publicvoid doGet(...) {
String action = (String)req.getParameter("action");
if (action.equals("GetMyObject")){
try {
res.setContentType("application/x-java-serialized-object");
ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
MyClass myObj = new MyClass();
out.writeObject(myObj);
out.flush();
}
} else { doSomethingElse(); }
}
----------APPLET ...
URL currentPage = getCodeBase();
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
int port = currentPage.getPort();
String urlSuffix = "/servlet/myServlet?action=GetMyObject";
URL dataURL = new URL(protocol, host, port, urlSuffix);
URLConnection connection = dataURL.openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
ObjectInputStream in = new ObjectInputStream(connection.getInputStream());
MyClass myObj = (MyClass)(in.readObject());
in.close();
--------------------------------------------------------------- Any ideas please..