File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet could not send Objects to an Applet

 
Richard Huges
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have an applet and a servlet. They use http and object-serialization. The communication between them works as long as I send objects only in one direction (either applet->servlet or servlet->applet). But when the servlet should return some objects straightly after receiving an object from the applet, the applet receives nothing.
Thanks

*********************************************************************************************
Applet Code (Method)
*********************************************************************************************
URL url = null;
URLConnection servletConnection = null;
Vector vStg = null;
try {
url = new URL("https://localhost:8080/servlet/vpl");
servletConnection = url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
servletConnection.setRequestProperty("Content-type","application/x-java-serialized-object");
ObjectOutputStream outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
Msg outobj = new Msg(Msg.GET_STG);
outputToServlet.writeObject(outobj);
outputToServlet.flush();
outputToServlet.close();
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
vStg = (Vector) inputFromServlet.readObject();
inputFromServlet.close();
}
catch(Exception g) {
g.printStackTrace();
}
return (vStg);
*********************************************************************************************
Servlet Code
*********************************************************************************************
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
ObjectOutputStream outputToApplet = null;
ObjectInputStream inputFromApplet = null;
try {
response.setContentType("application/x-java-serialized-object");
inputFromApplet = new ObjectInputStream(request.getInputStream());
System.out.println(inputFromApplet);
test = (Msg) inputFromApplet.readObject();
System.out.println(test);
if(test.getAuswahl() == 2) /*Msg.GET_STG*/{
outputToApplet = new ObjectOutputStream(response.getOutputStream());
outputToApplet.writeObject(mytestdat.vPlan);
outputToApplet.flush();
outputToApplet.close();
inputFromApplet.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
catch (java.lang.ClassNotFoundException g) {
g.printStackTrace();
}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it without closing the outputToServlet stream until after you read the input from servlet. I suspect that closing that stream closes the whole connection. Performing the flush() is enough to complete sending the object.
Bill
 
Richard Huges
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it, but there was no improvement
 
Richard Huges
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose, that I've tried now every sequence of
new ObjectOutputStream/-InputStream,
write/readObject, flush and close
I don't understand why it doesn't work
hopless Richard
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic